From: phpbug dot classvars at sub dot noloop dot net Operating system: Linux PHP version: 5.2.8 PHP Bug Type: Class/Object related Bug description: get_class_vars does not include visible private variable looking at subclass
Description: ------------ Even after bug #45862, #46761 and #46795 there is something really weird going on with get_class_vars(). It seems to be the consensus of the developers that get_class_vars() should return all properties of the given class that are _visible_ from the context calling get_class_vars() (nevermind that the docs claim "returns ... public properties of the class" (see #46795)). (Also, #31543 seems to contradict everything else) But get_class_vars() does not return visible private properties when invoked on a subclass. In the attached code, the second call to dumpClass should return 'private_a', as $private_a would still be visible in methods in A, even if the object in question actually is of type B. As a side note, I find it a bit strange that the behaviour of get_class_vars() function changed between 5.2.6 and 5.2.7 (it broke a real-world inhouse app here, for example) :) Reproduce code: --------------- <?php class A { private $private_a; public static function dumpClass($class) { print_r(get_class_vars($class)); } } class B extends A { private $private_b; } A::dumpClass('A'); A::dumpClass('B'); Expected result: ---------------- Array ( [private_a] => ) Array ( [private_a] => ) Actual result: -------------- Array ( [private_a] => ) Array ( ) -- Edit bug report at http://bugs.php.net/?id=46812&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46812&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46812&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46812&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46812&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46812&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46812&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46812&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46812&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46812&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46812&r=support Expected behavior: http://bugs.php.net/fix.php?id=46812&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46812&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46812&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46812&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46812&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46812&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46812&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46812&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46812&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46812&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46812&r=mysqlcfg