php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29095 array_merge loses references
Submitted: 2004-07-11 19:15 UTC Modified: 2004-07-11 22:59 UTC
From: alex at avannaproductions dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS: MacOS X 10.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alex at avannaproductions dot com
New email:
PHP Version: OS:

 

 [2004-07-11 19:15 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-11 22:59 UTC] curt@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 05:01:42 2025 UTC