|
Ryokotsusai -> 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...
|
|
|
|