|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-06-07 20:43 UTC] dsp@php.net
-Status: Open
+Status: Bogus
[2011-06-07 20:43 UTC] dsp@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Mon Mar 16 07:00:01 2026 UTC |
Description: ------------ When using array_merge() on an array of objects, the resulting array is linked to the source array(s) as if passed by reference so that modifying the resulting array after the merge ALSO modifies the source array. Test script: --------------- <?php $obj = (object) null; $obj->name = 'Bob'; $arrA = array(); $arrB = array($obj); // name = "Bob" $arrA = array_merge($arrA, $arrB); // Change name property of first element $arrA[0]->name = 'Joe'; print_r($arrA); // name = "Joe" print_r($arrB); // name = "Joe"; source array was modified, should still be "Bob Expected result: ---------------- Array ( [0] => stdClass Object ( [name] => Joe ) ) Array ( [0] => stdClass Object ( [name] => Bob ) ) Actual result: -------------- Array ( [0] => stdClass Object ( [name] => Joe ) ) Array ( [0] => stdClass Object ( [name] => Joe ) )