note 100920 deleted from language.oop5.visibility by danbrown
| From: | danbrown@php.net | Date: | Mon, 15 Nov 2010 13:11:33 +0000 |
| Subject: | note 100920 deleted from language.oop5.visibility by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174039@lists.php.net to get a copy of this message | ||
Note Submitter: Craig
----
This is in response to ryan lange below.
I suspect this is not a quirk.
The docs state: "Members declared as private may only be accessed by the class that defines the
member."
This means ChildClass2 *never* accesses the variable defined in the parent class, but always
accesses its own local values. Likewise, ParentClass can't access private vars set in
ChildClass2. If you want this behaviour, then you should use the protected keyword, not private.
To try explain what's happening:
ChildClass2 sets $this->foo, but in reality it's creating a localised variable on the fly
(ChildClass2::foo, rather than setting ParentClass::foo). I can't find a reference to it, but I
would hazard a guess that vars created in this fashion are private by default.
Also ParentClass never sets ParentClass::foo to "foo", because ParentClass::__construct()
is never called (only ChildClass2's construct is called).
This is why, when you call $child2->foo() you get nothing back, because the ParentClass
can't access the var ChildClass2::foo, and ParentClass::foo was never set to a value.