]> granicus.if.org Git - php/commitdiff
Fixed #71837 (Wrong arrays behaviour)
authorXinchen Hui <laruence@gmail.com>
Thu, 17 Mar 2016 14:41:41 +0000 (07:41 -0700)
committerXinchen Hui <laruence@gmail.com>
Thu, 17 Mar 2016 14:41:41 +0000 (07:41 -0700)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug71837.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 419fbc499a42596ef4ce52d19d3b0a1dbe2e206b..5329582dad2baf789d369c29346e516b6cf42f24 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ PHP                                                                        NEWS
     (Laruence)
 
 - Standard:
+  . Fixed bug #71837 (Wrong arrays behaviour). (Laruence)
   . Fixed bug #71840 (Unserialize accepts wrongly data). (Ryat, Laruence)
 
 31 Mar 2016 PHP 7.0.5
index 4d2c45ec51a97f9b6eb93931ab319ed34adb4ff4..4ff373a0b0265cf9bf82a3bb9a22b239c98b2a1c 100644 (file)
@@ -3198,6 +3198,9 @@ static inline void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETE
                src  = Z_ARRVAL_P(arg);
                dest = Z_ARRVAL_P(return_value);
                ZEND_HASH_FOREACH_KEY_VAL(src, idx, string_key, src_entry) {
+                       if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) {
+                               src_entry = Z_REFVAL_P(src_entry);
+                       }
                        if (string_key) {
                                if (Z_REFCOUNTED_P(src_entry)) {
                                        Z_ADDREF_P(src_entry);
@@ -3235,6 +3238,9 @@ static inline void php_array_merge_or_replace_wrapper(INTERNAL_FUNCTION_PARAMETE
                src  = Z_ARRVAL_P(arg);
                dest = Z_ARRVAL_P(return_value);
                ZEND_HASH_FOREACH_STR_KEY_VAL(src, string_key, src_entry) {
+                       if (UNEXPECTED(Z_ISREF_P(src_entry) && Z_REFCOUNT_P(src_entry) == 1)) {
+                               src_entry = Z_REFVAL_P(src_entry);
+                       }
                        if (string_key) {
                                if (Z_REFCOUNTED_P(src_entry)) {
                                        Z_ADDREF_P(src_entry);
diff --git a/ext/standard/tests/array/bug71837.phpt b/ext/standard/tests/array/bug71837.phpt
new file mode 100644 (file)
index 0000000..686d144
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Bug #71837 (Wrong arrays behaviour)
+--FILE--
+<?php
+
+$p = array(array());
+array_push($p[0], array(100));
+
+$c = array_merge($p, array());
+$c[0][0] = 200;
+
+print_r($p);
+
+?>
+--EXPECT--
+Array
+(
+    [0] => Array
+        (
+            [0] => Array
+                (
+                    [0] => 100
+                )
+
+        )
+
+)