#34128 [NEW]: Problem accessing the value of static class members from sub-classes

From: Date: Sun, 14 Aug 2005 13:08:18 +0000
Subject: #34128 [NEW]: Problem accessing the value of static class members from sub-classes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-83555@lists.php.net to get a copy of this message
From: tim dot rodger at gmail dot com Operating system: Debian Sarge (kernel 2.6.12) PHP version: 5.0.4 PHP Bug Type: Class/Object related Bug description: Problem accessing the value of static class members from sub-classes Description: ------------ When a static (either public or protected) class member is initialised to a default value in a class declaration and later the value is over-written in the class where it is decalred, inheriting classes cannot access the new member value. In the example class Bar can access the value assigned to Foo's $name member, but Bar cannot access the value assigned to Foo's $age member. If the $age member is assigned a value inside class Bar (in the constructor for example) then the code works as expected. Reproduce code: --------------- <?php class Foo{ protected static $name; protected static $age = NULL; public function __construct($name, $age){ self::$name = $name; self::$age = $age;} protected static function getName(){return self::$name;} protected static function getAge(){return self::$age;} } class Bar extends Foo { public function __construct($name, $age){ parent::__construct($name, $age);} public function display(){ print "name = '" . self::$name . "'\ngetName() = '" . self::getName() . "'\nage = '" . self::$age . "'\ngetAge() = '" . self::getAge() . "'\n";} } $b = new Bar('test', 100); $b->display(); ?> Expected result: ---------------- name = 'test' getName() = 'test' age = '100' getAge() = '100' Actual result: -------------- name = 'test' getName() = 'test' age = '' getAge() = '100' -- Edit bug report at http://bugs.php.net/?id=34128&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34128&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34128&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34128&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=34128&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=34128&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=34128&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=34128&r=needscript Try newer version: http://bugs.php.net/fix.php?id=34128&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=34128&r=support Expected behavior: http://bugs.php.net/fix.php?id=34128&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=34128&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=34128&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=34128&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34128&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=34128&r=dst IIS Stability: http://bugs.php.net/fix.php?id=34128&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=34128&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=34128&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=34128&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=34128&r=mysqlcfg

« previous php.bugs (#83555) next »