|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43600 static array
Submitted: 2007-12-14 21:23 UTC Modified: 2007-12-18 14:08 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: 6eWmA67gxAebq at jeanpierredaviau dot com Assigned: colder (profile)
Status: Not a bug Package: Class/Object related
PHP Version: 5.2CVS-2007-12-14 (snap) OS: win xp
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:
2 + 35 = ?
Subscribe to this entry?

 [2007-12-14 21:23 UTC] 6eWmA67gxAebq at jeanpierredaviau dot com
a static array dont retain a modification

PHP 5.2.2 (cli) (built: May  2 2007 19:18:26)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
    with DBG v2.15.5, (C) 2000,2007, by Dmitri Dmitrienko

Reproduce code:

Expected result:
print_r (Registre::getRegistre());
    [0] => info2 Object 
            [var] => 0 
            [class] => info2 

Actual result:
$a = new info(); 
$b = new info2(); 
$a = NULL; 
print_r (Registre::getRegistre());   //dont print the changed self::$leRegistre 
    [0] => info Object 
            [var] => 0 
            [class] => info 

    [1] => info2 Object 
            [var] => 0 
            [class] => info2 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-15 01:06 UTC]
Clarifying example:


class foo {
	static $foo = array();
	static function test($obj) {
		self::$foo[] = $obj;

class bar {
	public function __construct() {

$a = new bar;
var_dump(foo::$foo); // He expects empty array

 [2007-12-18 12:42 UTC]
Documentation says:
"When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object that was assigned. This behaviour is the same when passing instances to a function."

Using PHP 5.3.0-dev (cli) (built: Dec 17 2007 10:53:40):


$obj = new stdClass;

$a = $obj;


var_dump($a, $obj);



object(stdClass)#1 (0) {
 [2007-12-18 14:08 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

unset($a) or $a = NULL; only affects the current variable, unless this variable represents the last one holding a reference to the object, the object won't be destroyed.

For example:

$a = new StdClass;
$b = $a;
$a = NULL; // $b is still holding the instance.

same with unset:

$a = new stdClass;
$b = $a;
unset($a); // $b is still holding the var

You could have the object destroyed by $a = NULL; if $b was a reference to $a. but in case of arrays the array element is not removed: you should do such cleaning manually.
The behavior you notice is expected and has nothing specific to do with "static arrays".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 13:01:29 2024 UTC