Bug #71950 [Opn->Nab]: static variables are incorrect after call parent::method()
| From: | requinix@php.net | Date: | Sun, 03 Apr 2016 22:19:46 +0000 |
| Subject: | Bug #71950 [Opn->Nab]: static variables are incorrect after call parent::method() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200329@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71950&edit=1
ID: 71950
Updated by: requinix@php.net
Reported by: michael dot bilcot at gmail dot com
Summary: static variables are incorrect after call
parent::method()
-Status: Open
+Status: Not a bug
Type: Bug
Package: Class/Object related
Operating System: Windows 10 64
PHP Version: Irrelevant
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
Static variables will persist their values across every call. *Every* call.
Previous Comments:
------------------------------------------------------------------------
[2016-04-03 18:18:46] michael dot bilcot at gmail dot com
Description:
------------
When you call parent::method() and there is a static variable in this, the value returned to all
inherited objects is the same
Test script:
---------------
class A
{
function a()
{
static $i;
if (!$i)
{
$i = $this->value;
}
return $i;
}
}
class B extends A
{
public $value = 'B';
}
class C extends A
{
public $value = 'C';
function a()
{
return parent::a();
}
}
$b = new B;
echo $b->a();
$c = new C;
echo $c->a();
Expected result:
----------------
BC
Actual result:
--------------
BB
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71950&edit=1