Bug #67625 [NEW]: Access to undeclared static property

From: Date: Tue, 15 Jul 2014 14:56:28 +0000
Subject: Bug #67625 [NEW]: Access to undeclared static property
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186636@lists.php.net to get a copy of this message
From: tb at bytecode dot se Operating system: Ubuntu 14.04 PHP version: 5.5.14 Package: Class/Object related Bug Type: Bug Bug description:Access to undeclared static property Description: ------------ I'm running a plain vanilla PHP installation in Ubuntu (both the standard 5.5.9 and the developer version available which is 5.5.14). When I run the script below from the command line I get the error message "PHP Fatal error: Access to undeclared static property: DummyTest\Lib\Database\TPDO::$config in /home/thomas/src/bugtest/staticclass.php on line 50" If I change all static::$config[$name] to self::$config[$name] then it works without errors. I've also tested the same code in HHVM version 3.1.0 without any errors. (Tested both with static:: and self:: ) On line 49 I call get_called_class() to check which class is called. In my tiny little world I would expect it to say "DummyTest\SystemConfig" which it does in HHVM. But in PHP it says "DummyTest\Lib\Database\TPDO". Test script: --------------- <?php namespace DummyTest\Lib { class TObject { public function __construct() { } } class TComponent extends \DummyTest\Lib\TObject { public function __construct() { parent::__construct(); } } class TSingletonComponent extends \DummyTest\Lib\TComponent { public function __construct() { parent::__construct(); } } class TDatabase extends \DummyTest\Lib\TSingletonComponent { public function __construct() { parent::__construct(); } public static function Init() { $db = new \DummyTest\Lib\Database\TPDO(); } } } namespace DummyTest\Lib\Database { class TDatabase extends \DummyTest\Lib\TComponent { public function __construct() { parent::__construct(); } } class TPDO extends \DummyTest\Lib\Database\TDatabase { protected $pdo; public function __construct() { parent::__construct(); echo \DummyTest\SystemConfig::Get('xxx'); // <-- This fails in PHP } } } namespace DummyTest { class SystemConfig { protected static $config = array(); public function Get($name) { echo get_called_class().PHP_EOL; // <-- Gives different result in PHP and HHVM if(isset(static::$config[$name])) { return static::$config[$name]; } return null; } public function Set($name, $value) { static::$config[$name] = $value; } } SystemConfig::Set('xxx', 'yyy'); \DummyTest\Lib\TDatabase::Init(); } Expected result: ---------------- DummyTest\SystemConfig yyy Actual result: -------------- DummyTest\Lib\Database\TPDO PHP Fatal error: Access to undeclared static property: DummyTest\Lib\Database\TPDO::$config in /home/thomas/src/bugtest/staticclass.php on line 50 -- Edit bug report at https://bugs.php.net/bug.php?id=67625&edit=1 --

« previous php.bugs (#186636) next »