Example:This will error out, you access a protected variable that is accessible only from the class itself or derived classes (using $this->var).
class Parent { protected $var = "test"; function blah($somevar) { ... } }
class Child extends Parent { ... }
$parent = new Parent; print $parent->var; //ouputs "test"
Gives error for the same reason as above. But if you declare a public method in Child class:$child = new Child; print $child->var; //outputs nothing
function getVar() {
return $this->var;
}
, then this would work:
print $child->getVar();
Protected variables are accessible also from derived classes, private are not. But both are NOT accessible from outside (e.g. using $a=new A; $a->var;), but only from within class methods (using $this->var).
as you can see $var is only accessible by objects that are specifically Parents, not Children.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php