Bug #55789 [Opn->Bgs]: Late Static Bindings
| From: | stas@php.net | Date: | Tue, 27 Dec 2011 10:10:07 +0000 |
| Subject: | Bug #55789 [Opn->Bgs]: Late Static Bindings | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-166106@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55789&edit=1
ID: 55789
Updated by: stas@php.net
Reported by: kashpur dot kostya at gmail dot com
Summary: Late Static Bindings
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Windows7
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Declare inst() as static if you call it statically. Otherwise PHP interprets it
as a dynamic, which for BC reasons is allowed.
Previous Comments:
------------------------------------------------------------------------
[2011-09-26 23:18:57] kashpur dot kostya at gmail dot com
Description:
------------
If I call method of the class "B" that implements class "A" that uses static,
under some class "C" it tries to get static property of the "C", but not of the
"B". And if I try to call B::inst() not under some class it works fine.
Test script:
---------------
class A
{
public static $_a = null;
private function __construct()
{}
private function __clone()
{}
public function inst()
{
if (is_null(static::$_a))
{
static::$_a = new static();
}
return static::$_a;
}
}
class B extends A
{
}
class C
{
public function __construct()
{
B::inst();
}
}
Expected result:
----------------
B::$_a
Actual result:
--------------
Fatal error: Access to undeclared static property: C::$_a
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55789&edit=1