php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34128 Problem accessing the value of static class members from sub-classes
Submitted: 2005-08-14 15:08 UTC Modified: 2005-08-14 18:53 UTC
From: tim dot rodger at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.0.4 OS: Debian Sarge (kernel 2.6.12)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tim dot rodger at gmail dot com
New email:
PHP Version: OS:

 

 [2005-08-14 15:08 UTC] 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'


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-14 15:12 UTC] tony2001@php.net
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


 [2005-08-14 18:05 UTC] tim dot rodger at gmail dot com
I've installed the latest snap-shot on a second debian machine (with a 2.6.9 kernel), since I didn't want to replace php on the machine i found the bug on. I've just now tested the bug under the latest version 5.1.0-dev and it's fixed.
 [2005-08-14 18:53 UTC] tony2001@php.net
Fixed -> closed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 09:01:34 2025 UTC