php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67332 The local static variables
Submitted: 2014-05-23 07:41 UTC Modified: 2014-05-23 08:16 UTC
From: dreamsxin at qq dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.28 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dreamsxin at qq dot com
New email:
PHP Version: OS:

 

 [2014-05-23 07:41 UTC] dreamsxin at qq dot com
Description:
------------
Local static variables, in the parent and child classes, is the same.
In 5.5.7 has same proplem.

https://bugs.php.net/bug.php?id=53155

Test script:
---------------
<?php

class Test {

	public static function hello()
	{
		static $my;
		if ($my) {
			$my = '2';
		} else {
			$my = '1';
		}
		var_dump($my);
	}
}

class Test2 extends Test {
}

Test::hello();
Test::hello();
Test2::hello();

Expected result:
----------------
string(1) "1"
string(1) "2"
string(1) "2"

Actual result:
--------------
string(1) "1"
string(1) "2"
string(1) "1"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-23 08:16 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2014-05-23 08:16 UTC] johannes@php.net
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

The method is still the same in both cases. If you need object-specific state use a property. If you truly (I'd question your design) class hierarchy-specific static state you can do something using late static binding and i.e. an static array ...
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 08:00:01 2026 UTC