|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71950 static variables are incorrect after call parent::method()
Submitted: 2016-04-03 18:18 UTC Modified: 2016-04-09 08:28 UTC
From: mika018 at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: Irrelevant OS: Windows 10 64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
17 - 11 = ?
Subscribe to this entry?

 [2016-04-03 18:18 UTC] mika018 at gmail dot com
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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-03 22:19 UTC]
-Status: Open +Status: Not a bug
 [2016-04-03 22:19 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Static variables will persist their values across every call. *Every* call.
 [2016-04-09 08:28 UTC] mika018 at gmail dot com
-: michael dot bilcot at gmail dot com +: mika018 at gmail dot com
 [2016-04-09 08:28 UTC] mika018 at gmail dot com
Ok thank you

My test was distorted because of "a" method is the A class construct too.
Sorry, my bad
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Dec 05 14:01:27 2023 UTC