#34128 [Opn->Fbk]: Problem accessing the value of static class members from sub-classes
| From: | tony2001@php.net | Date: | Sun, 14 Aug 2005 13:12:39 +0000 |
| Subject: | #34128 [Opn->Fbk]: Problem accessing the value of static class members from sub-classes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-83557@lists.php.net to get a copy of this message | ||
ID: 34128
Updated by: tony2001@php.net
Reported By: tim dot rodger at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: Class/Object related
Operating System: Debian Sarge (kernel 2.6.12)
PHP Version: 5.0.4
New Comment:
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
Previous Comments:
------------------------------------------------------------------------
[2005-08-14 15:08:17] tim dot rodger at gmail dot com
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 this bug report at http://bugs.php.net/?id=34128&edit=1