navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

Microsoft MVP

 

Beginner PHP OOP Questions

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> Beginner PHP OOP Questions
Page: [1]
 
lsfphelpls

 

Posts: 443
Joined: 3/16/2005
Status: offline

 
Beginner PHP OOP Questions - 3/30/2008 16:18:35   
PHP OOP Q:
vars such
private $var1; // are valid , or must get a start value ?

Inside a class function vars can declared with or without private/public ? WHAT IS THE DIFFERENCE ?
public function getSum() {
private $var1;
$var2=7;
.....
.....
} // end method

This is correct SQL Statement:
private $TableName="reserv";
private $first="Sam";
private $last="Smith";
public function getSum() {
$SQLstring="INSERT INTO $this->TableName VALUES(NULL,'$this->first','$this->last')";
.....
.....
} // end method

When I use an object in a subpage the corresponding class of this object must be attached in a php file or be in the <head> ? May ONLY have this class in the homepage ?
Ryokotsusai

 

Posts: 248
Joined: 10/5/2005
Status: offline

 
RE: Beginner PHP OOP Questions - 3/31/2008 0:48:04   
quote:

vars such
private $var1; // are valid , or must get a start value ?


Yes you can declare them with or without a starting value:
public $var; // is valid
public $var2 = 'value'; // is valid


quote:

Inside a class function vars can declared with or without private/public ? WHAT IS THE DIFFERENCE ?
public function getSum() {
private $var1;
$var2=7;


to declare a variable, you must use public, private, or protected. To create a function you can use the same declarations, or you can leave them out and it will assume public.

public function func1() {}

// is exactly the same as

function func1() {}


as for the different types of declarations,

public: can be used outside the class ie:
class test {

public $var = "Test";

}

$class = new test;
echo $class->$var; //will echo "Test"


private / protected: I do not remember what the difference is between these 2, but using these will prevent that variable or function from being called outside of the class.

Hope that helps some...

_____________________________

The world is more like it is now than it ever has been before.
--Dwight Eisenhower

(in reply to lsfphelpls)
lsfphelpls

 

Posts: 443
Joined: 3/16/2005
Status: offline

 
RE: Beginner PHP OOP Questions - 3/31/2008 2:32:04   
SQL statement is correct ?

Inside a class function, vars can declared with private/public or ONLY without ?
public function getSum() {
private $var1; // wrong ?
$var2=7; // correct ?
.....
.....
} // end method

When I use an object in a subpage the corresponding class of this object must be attached in a php file or be in the <head> ? May ONLY have this class in the homepage and access object of this class from the subpage ? in other words every time I use[in a file] $object= new className(); the class must exist in this file ?

(in reply to Ryokotsusai)
Ryokotsusai

 

Posts: 248
Joined: 10/5/2005
Status: offline

 
RE: Beginner PHP OOP Questions - 3/31/2008 4:32:17   
quote:

SQL statement is correct ?


If you are refering to this one:

quote:

$SQLstring="INSERT INTO $this->TableName VALUES(NULL,'$this->first','$this->last')";


then, it looks fine to me, that is how you would call those variables.

quote:


public function getSum() {
private $var1; // wrong ?
$var2=7; // correct ?
.....
.....
} // end method


inside of a method, $var2=7, would be correct

the class needs to be in a connected page or in the same page, ie:

class.php
<?php

class test {

function test_function() {
}
 
}

?>

index.php
<?php
include 'class.php';

$class = new test;
?>

would work fine

_____________________________

The world is more like it is now than it ever has been before.
--Dwight Eisenhower

(in reply to lsfphelpls)
lsfphelpls

 

Posts: 443
Joined: 3/16/2005
Status: offline

 
RE: Beginner PHP OOP Questions - 4/21/2008 11:05:55   
answer asap this:
i)in js in a for loop the counter to increment one by one must be ...,++j;) or ...,j++;)
ii)null value considered and the value="" ?
iii)to set css text color to Transparent what to do ?

(in reply to Ryokotsusai)
alihammad

 

Posts: 1
Joined: 6/3/2008
Status: offline

 
RE: Beginner PHP OOP Questions - 6/3/2008 2:47:01   
Please tell me how to access global variables in a class..
Like if i want to access form variables through $_POST or $_GET .?
i did this and didnt work

class declaration

$form= new formcheck();
$form->printvar();

class definition

class formcheck()
{
protected $a;

function _construct()
{
$this->a= $_POST['name']
}
function printvar()
{
echo $this->a;

}

}

(in reply to lsfphelpls)
Page:   [1]

All Forums >> Web Development >> General Web Development >> Beginner PHP OOP Questions
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts