]> granicus.if.org Git - php/commitdiff
- MFH: Fixed bug #48854 (array_merge_recursive modifies arrays after first one)
authorFelipe Pena <felipe@php.net>
Wed, 8 Jul 2009 18:23:08 +0000 (18:23 +0000)
committerFelipe Pena <felipe@php.net>
Wed, 8 Jul 2009 18:23:08 +0000 (18:23 +0000)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug48854.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5d7413c3d8ea814cc0baa5aee1a4a106312a2de8..e8838c7fd3da852525386c1afd7319d6c89d8300 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ PHP                                                                        NEWS
 - Fixed spl_autoload_unregister/spl_autoad_functions wrt. Closures and
   Functors. (Christian Seiler)
 
+- Fixed bug #48854 (array_merge_recursive modifies arrays after first one).
+  (Felipe)
 - Fixed bug #48788 (RecursiveDirectoryIterator doesn't descend into symlinked
   directories). (Ilia)
 - Fixed bug #48771 (rename() between volumes fails and reports no error on 
index 798895e180e86647f143d7f8d05a4dd6a657baf9..e9a68463c6a3e3b37d00e802563509fdccacd7de 100644 (file)
@@ -2305,6 +2305,7 @@ static void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETERS, int
        array_init_size(return_value, init_size);
 
        for (i = 0; i < argc; i++) {
+               SEPARATE_ZVAL(args[i]);
                if (!replace) {
                        php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), recursive TSRMLS_CC);
                } else if (recursive && i > 0) { /* First array will be copied directly instead */
diff --git a/ext/standard/tests/array/bug48854.phpt b/ext/standard/tests/array/bug48854.phpt
new file mode 100644 (file)
index 0000000..0908637
--- /dev/null
@@ -0,0 +1,43 @@
+--TEST--
+Bug #48854 (array_merge_recursive modifies arrays after first one)
+--FILE--
+<?php
+
+$array1 = array(
+       'friends' => 5,
+       'children' => array(
+               'dogs' => 0,
+       ),
+);
+
+$array2 = array(
+       'friends' => 10,
+       'children' => array(
+               'cats' => 5,
+       ),
+);
+
+$merged = array_merge_recursive($array1, $array2);
+
+var_dump($array1, $array2);
+
+?>
+--EXPECTF--
+array(2) {
+  [%u|b%"friends"]=>
+  int(5)
+  [%u|b%"children"]=>
+  array(1) {
+    [%u|b%"dogs"]=>
+    int(0)
+  }
+}
+array(2) {
+  [%u|b%"friends"]=>
+  int(10)
+  [%u|b%"children"]=>
+  array(1) {
+    [%u|b%"cats"]=>
+    int(5)
+  }
+}