Edit report at https://bugs.php.net/bug.php?id=53155&edit=1
ID: 53155
Comment by: ash at itsash dot co dot uk
Reported by: frederic dot hardy at mageekbox dot net
Summary: conditional class creation does not reset static
variable in method
Status: Open
Type: Bug
Package: Scripting Engine problem
Operating System: FreeBSD
PHP Version: 5.3.3
Block user comment: N
Private report: N
New Comment:
I have the same issue on 5.3.6 on Ubuntu.
static::$classVariable with late static binding causes php to override the
parent
static variable.
When using static $methodVariable = 'first_value'; if this is later changed,
by
$methodVariable, when a new instance of that class is initiated, the
$methodVariable SHOULD be 'first_value', however UNEXPECTEDLY it carries over
from any prior instance.
Previous Comments:
------------------------------------------------------------------------
[2010-10-27 02:54:21] [email protected]
Probably related to bug #48623
------------------------------------------------------------------------
[2010-10-25 21:41:26] frederic dot hardy at mageekbox dot net
Description:
------------
when a class which extends a parent class with a method which define a static
variable is created then a condition is verified, the static variable is not
reset in the chield class.
Test script:
---------------
<?php
abstract class singleton
{
public static function getInstance()
{
static $instance = null;
if ($instance === null)
{
$instance = new static();
}
return $instance;
}
protected function __construct() {}
protected function __clone() {}
}
class a extends singleton {
}
var_dump(a::getInstance());
if (1 > 0)
{
class b extends a {}
}
var_dump(b::getInstance());
?>
Expected result:
----------------
object(a)#1 (0) {
}
object(b)#2 (0) {
}
Actual result:
--------------
object(a)#1 (0) {
}
object(a)#1 (0) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53155&edit=1