|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-07-15 15:01 UTC] tb at bytecode dot se
-Status: Open
+Status: Closed
[2014-07-15 15:01 UTC] tb at bytecode dot se
[2014-07-16 14:20 UTC] rasmus@php.net
-Status: Closed
+Status: Not a bug
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 06:00:01 2025 UTC |
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