Bug #53155 [Opn->Nab]: conditional class creation does not reset static variable in method
| From: | danack@php.net | Date: | Thu, 08 Jan 2015 20:35:40 +0000 |
| Subject: | Bug #53155 [Opn->Nab]: conditional class creation does not reset static variable in method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-189749@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53155&edit=1
ID: 53155
Updated by: danack@php.net
Reported by: frederic dot hardy at mageekbox dot net
Summary: conditional class creation does not reset static
variable in method
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: FreeBSD
PHP Version: 5.3.3
Block user comment: N
Private report: N
New Comment:
Yep, the code is behaving as it is defined in the language.
Previous Comments:
------------------------------------------------------------------------
[2012-10-26 16:14:48] dagguh at gmail dot com
Another proof that LSB produces bad code.
Just look at it.
There is no such thing as static inheritance, so maybe you should simply learn to
code.
------------------------------------------------------------------------
[2012-05-11 21:05:49] ash at itsash dot co dot uk
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.
------------------------------------------------------------------------
[2010-10-27 02:54:21] felipe@php.net
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