#29095 [Opn->Bgs]: array_merge loses references

From: Date: Sun, 11 Jul 2004 20:59:33 +0000
Subject: #29095 [Opn->Bgs]: array_merge loses references
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-62066@lists.php.net to get a copy of this message
ID: 29095 Updated by: curt@php.net Reported By: alex at avannaproductions dot com -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: MacOS X 10.3 PHP Version: Irrelevant New Comment: 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 array_merge will return a copy of the merged arrays. Previous Comments: ------------------------------------------------------------------------ [2004-07-11 19:15:50] alex at avannaproductions dot com Description: ------------ I'm not sure if this is a bug or actual accepted behavior, but array_merge seems to lose references. (I would assume array_merge_recursive does too, but I've not tested that.) I think it would be ideal behavior if this did not happen, as I've just come upon a real world situation where my desired behavior would be very useful. Test on both PHP 4.3.6 and July 10th snapshot of PHP 5. Reproduce code: --------------- $one=array(1,2,3); $two=array(4,5,6); $three=&$two; foreach($one as $val) echo "$val<br>"; foreach($three as $val) echo "$val<br>"; echo "-------------<br>"; $four=array_merge($one,&$three); $two[0]="x"; $two[1]="x"; $two[2]="x"; foreach($four as $val) echo "$val<br>"; Expected result: ---------------- 1 2 3 4 5 6 ------------- 1 2 3 x x x Actual result: -------------- 1 2 3 4 5 6 ------------- 1 2 3 4 5 6 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29095&edit=1

« previous php.bugs (#62066) next »