#48854 [NEW]: array_merge_recursive modifies arrays after first one
| From: | stakadush at yahoo dot com | Date: | Wed, 08 Jul 2009 15:43:05 +0000 |
| Subject: | #48854 [NEW]: array_merge_recursive modifies arrays after first one | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-139484@lists.php.net to get a copy of this message | ||
From: stakadush at yahoo dot com
Operating system: Ubuntu 9.04
PHP version: 5.3.0
PHP Bug Type: Scripting Engine problem
Bug description: array_merge_recursive modifies arrays after first one
Description:
------------
array_merge_recursive seems to modify the arrays which are passed,
except for the first one.
it turns all first-level non-array elements, into arrays.
the code will explain it better :)
Reproduce code:
---------------
$array1 = array(
'friends' => 5,
'children' => array(
'dogs' => 0,
),
);
$array2 = array(
'friends' => 10,
'children' => array(
'cats' => 5,
),
);
echo sprintf("Second array before: %s\n", print_r($array2, true));
$merged = array_merge_recursive($array1, $array2);
echo sprintf("Second array after: %s\n", print_r($array2, true));
Expected result:
----------------
to have $array2 untouched after array_merge_recursive:
Array
(
[friends] => 10
[children] => Array
(
[cats] => 5
)
)
Actual result:
--------------
$array2 gets modified after array_merge_recursive, and every first-
level no-array element, gets turned into an array (in this case
'friends')...
Array
(
[friends] => Array
(
[0] => 10
)
[children] => Array
(
[cats] => 5
)
)
--
Edit bug report at http://bugs.php.net/?id=48854&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48854&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48854&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48854&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=48854&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48854&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=48854&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=48854&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=48854&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=48854&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=48854&r=support
Expected behavior: http://bugs.php.net/fix.php?id=48854&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=48854&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=48854&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=48854&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48854&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=48854&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=48854&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=48854&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=48854&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=48854&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=48854&r=mysqlcfg