|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25222 Broken references while using array_pop in a tree / linked list
Submitted: 2003-08-24 10:18 UTC Modified: 2003-08-24 23:05 UTC
From: kevin at kevin-online dot com Assigned:
Status: Closed Package: *Programming Data Structures
PHP Version: 4.3.2 OS: Gentoo Linux (2.4.20-gentoo-r2)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kevin at kevin-online dot com
New email:
PHP Version: OS:


 [2003-08-24 10:18 UTC] kevin at kevin-online dot com
While building up a tree structure, i got strange troubles with some broken references. 
I used an array as stack holding references to objects. Some references within the object were broken after using a reference returned by array_pop.
PHP 4.3.2-r4

Reproduce code:
class Gnaa {
	var $something;
	var $name;
	function Gnaa( $name ) { $this->name = $name;}
	function setGnaa( &$something ) { $this->something = &$something; }
	function &getGnaa() { return $something; }

$a =& new Gnaa("a");
$stack[] = &$a;

$b =& new Gnaa("b");
$stack[] = &$b;

$child = &array_pop($stack); // should be &$b
$child->setGnaa( &$a );

print_r($child); // output differs!
print_r( $b );   // 

Expected result:
That $b has the reference to $a, because $child should be a reference to $b.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-24 23:05 UTC]
fixed in PHP 5. (won't fix in PHP 4)

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 15:01:32 2024 UTC