if it is not declared PHP 5 declares it as public, but it is a good practice to always define it. Here is how the visibility works:
PHP Code:
class myClass {
public $public="public";
private $private="private";
protected $protected="protected";
public function print_vars() {
echo $this->public;
echo $this->private;
echo $this->protected;
}
}
class myClass2 extends myClass {
public function print_vars2() {
echo $this->public;
echo $this->private;
echo $this->protected;
}
}
$test1=new myClass;
$test2=new myClass2;
Here is how it would output:
echo $test1->public; - "public"
echo $test1->private; - fatal error
echo $test1->protected; - fatal error
echo $test2->public; - "public"
echo $test2->private; - undefined
echo $test2->protected; - fatal error
$test1->print_vars(); - "public" "private" "protected"
$test2->print_vars2(); - "public" undefined "protected"
Bookmarks