#45097 [Opn->Bgs]: Magic __get() can't access inherited properties

From: Date: Fri, 30 May 2008 11:58:51 +0000
Subject: #45097 [Opn->Bgs]: Magic __get() can't access inherited properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125373@lists.php.net to get a copy of this message
ID: 45097 Updated by: felipe@php.net Reported By: ndaugherty987 at gmail dot com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: linux PHP Version: 5.2.6 New Comment: This is expected, use protected/public visibility. Previous Comments: ------------------------------------------------------------------------ [2008-05-26 18:54:47] ndaugherty987 at gmail dot com Description: ------------ The magic overloading function __get() can't seem to access inherited, non-visible properties. If you overload with __get() in a base class, then extend that class, the base class's __get() will return NULL when accessing an inaccessible property of the child class. The __get() function doesn't even see the property as being set (if you run an isset($name) in the __get() call, it returns false. Reproduce code: --------------- class testParent { function __get($name){ return $this->$name; } } class testChild extends testParent { private $testVar = 'Bar'; } $t = new testChild; echo 'Foo: ' . $t->testVar; Expected result: ---------------- You would expect the code to output 'Foo: Bar'. instead, it outputs 'Foo:', because the __get() in testParent apparently can't see the private vars in testChild. Actual result: -------------- Output's 'Foo:', withOUT the 'Bar' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45097&edit=1

« previous php.bugs (#125373) next »