#45097 [NEW]: Magic __get() can't access inherited properties

From: Date: Mon, 26 May 2008 18:54:47 +0000
Subject: #45097 [NEW]: Magic __get() can't access inherited properties
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-125267@lists.php.net to get a copy of this message
From: ndaugherty987 at gmail dot com Operating system: linux PHP version: 5.2.6 PHP Bug Type: Class/Object related Bug description: Magic __get() can't access inherited properties 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 bug report at http://bugs.php.net/?id=45097&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45097&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45097&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45097&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45097&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45097&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45097&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45097&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45097&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45097&r=support Expected behavior: http://bugs.php.net/fix.php?id=45097&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45097&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45097&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45097&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45097&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45097&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45097&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45097&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45097&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45097&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45097&r=mysqlcfg

« previous php.bugs (#125267) next »