Bug #67625 [Opn->Csd]: Access to undeclared static property

From: Date: Tue, 15 Jul 2014 15:01:10 +0000
Subject: Bug #67625 [Opn->Csd]: Access to undeclared static property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186638@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67625&edit=1

 ID:                 67625
 User updated by:    tb at bytecode dot se
 Reported by:        tb at bytecode dot se
 Summary:            Access to undeclared static property
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Ubuntu 14.04
 PHP Version:        5.5.14
 Block user comment: N
 Private report:     N

 New Comment:

Stupid misstake where I forgot to declare the Get/Set methods as static.
So the problem will be moved over to the guys at Facebook instead =)


Previous Comments:
------------------------------------------------------------------------
[2014-07-15 14:56:28] tb at bytecode dot se

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 this bug report at https://bugs.php.net/bug.php?id=67625&edit=1


Thread (3 messages)

« previous php.bugs (#186638) next »