|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-14 15:12 UTC] tony2001@php.net
[2005-08-14 18:05 UTC] tim dot rodger at gmail dot com
[2005-08-14 18:53 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 09 02:00:01 2025 UTC |
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'