|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-04-20 10:53 UTC] colder@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Thu Jan 29 17:00:02 2026 UTC |
Description: ------------ If you have a child class that inherits from a parent class that implements __get and __set and you access a private property from within these functions, then you will get a notice "Undefined property" when trying to access this property from an instance of the child class. If you try accessing the properties from an instance of the parent class, it works as expected. Reproduce code: --------------- class ParentClass { private $parentMessage = "Hello, from parent!"; private function __get($property) { echo "__get($$property)\n"; return $this->$property; } private function __set($property, $value) { echo "__set($$property, $value)\n"; $this->$property = $value; } } class ChildClass extends ParentClass { private $childMessage = "Hello, from child!"; } $parent = new ParentClass(); echo $parent->parentMessage . "\n"; $child = new ChildClass(); echo $child->childMessage . "\n"; Expected result: ---------------- __get($parentMessage) Hello, from parent! __get($childMessage) Hello, from child! Actual result: -------------- __get($parentMessage) Hello, from parent! __get($childMessage) Notice: Undefined property: ChildClass::$childMessage in C:\www\bug.php on line 11