array_merge() and objects

From: Date: Fri, 05 Oct 2001 23:33:56 +0000
Subject: array_merge() and objects
Groups: php.dev 
Request: Send a blank email to php-dev+get-67388@lists.php.net to get a copy of this message
array_merge() doesn't work if there are objects in your array. Here is a small test case. <?php class test { var $one; var $two; function test($one, &$two) { $this->one = $one; $this->two = &$two; } } $x = 6; $a = new test(1, &$x); $b = new test(2, &$x); $c = new test(3, &$x); $aa = array($a, $b, $c); $d = new test(4, &$x); $e = new test(5, &$x); $f = new test(1, &$x); $bb = array($d, $e, $f); $arr = array_merge($aa, $bb); // array_merge_recursive doesn't do this either var_dump($arr); ?> The results array(6) { [0]=> object(test)(2) { ["one"]=> int(1) ["two"]=> &int(6) } [1]=> object(test)(2) { ["one"]=> int(2) ["two"]=> &int(6) } [2]=> object(test)(2) { ["one"]=> int(3) ["two"]=> &int(6) } [3]=> object(test)(2) { ["one"]=> int(4) ["two"]=> &int(6) } [4]=> object(test)(2) { ["one"]=> int(5) ["two"]=> &int(6) } [5]=> object(test)(2) { ["one"]=> int(1) ["two"]=> &int(6) } } It should only be a FIVE element array. As elements 0 and 5 are exactly the same. I can only assume that this is beyond the scope of the function, but why? Seems like it would be pretty easy to do. -Chris

« previous php.dev (#67388) next »