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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
42 + 46 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 05:01:27 2024 UTC