Don't have the possibilities to try it out now, but I think you are wrong:

Example:

class Parent {
    protected $var = "test";
    function blah($somevar) {
        ...
    }
}

class Child extends Parent {
    ...
}

$parent = new Parent;
print $parent->var; //ouputs "test"
This will error out, you access a protected variable that is accessible only from the class itself or derived classes (using $this->var).

$child = new Child;
print $child->var; //outputs nothing
Gives error for the same reason as above. But if you declare a public method in Child class:
function getVar() {
return $this->var;
}
, then this would work:
print $child->getVar();

as you can see $var is only accessible by objects that are specifically Parents, not Children.
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).



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to