note 101995 deleted from language.oop5.visibility by danbrown
| From: | danbrown@php.net | Date: | Sat, 22 Jan 2011 00:43:04 +0000 |
| Subject: | note 101995 deleted from language.oop5.visibility by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175988@lists.php.net to get a copy of this message | ||
Note Submitter: bryan dot thale at motorola dot com
----
In reply to ryan dot m dot lange:
The behavior of your ChildClass2 class is exactly what should be expected.
The constructor of ChildClass2 is not setting ParentClass::foo because that member is private and
not visible to ChildClass2. Instead, it is dynamically defining and setting a new public
$child2->foo member.
$child2->foo() outputs nothing because foo() is inherited from ParentClass and the private
ParentClass::foo member is unset. ParentClass's constructor is not automatically invoked by
PHP since ChildClass2 defines its own constructor. ChildClass2::__construct() would have to
explicitly invoke parent::__construct() if you wanted to chain constructors.
$child2->bar() outputs the value of $child2->foo since that is the member that is visible to
$child2.