]> granicus.if.org Git - php/commitdiff
Fixed bug #71660 (array_column behaves incorrectly after foreach by reference)
authorXinchen Hui <laruence@gmail.com>
Thu, 25 Feb 2016 08:07:22 +0000 (16:07 +0800)
committerXinchen Hui <laruence@gmail.com>
Thu, 25 Feb 2016 08:07:22 +0000 (16:07 +0800)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug71660.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 27dfe7383233d06842e1cb7d0146450ce8faa369..a7c80bd25c572dc4c960d57467827dd2d378f817 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,10 @@ PHP                                                                        NEWS
   . Fixed bug #71617 (private properties lost when unserializing ArrayObject).
     (Nikita)
 
+- Standard:
+  . Fixed bug #71660 (array_column behaves incorrectly after foreach by
+    reference). (Laruence)
+
 - Zip:
   . Update bundled libzip to 1.1.2. (Remi, Anatol)
 
index 5add302c4636c0542faaed030d91265a4928176f..def7d7c465b0d3ab15797af5be2da641d3977812 100644 (file)
@@ -3498,6 +3498,10 @@ static inline zval *array_column_fetch_prop(zval *data, zval *name, zval *rv)
                }
        }
 
+       if (prop) {
+               ZVAL_DEREF(prop);
+       }
+
        return prop;
 }
 
diff --git a/ext/standard/tests/array/bug71660.phpt b/ext/standard/tests/array/bug71660.phpt
new file mode 100644 (file)
index 0000000..c2d7192
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #71660 (array_column behaves incorrectly after foreach by reference)
+--FILE--
+<?php
+$arr = array('id' => 12345, 'name' => 'sam');
+foreach ($arr as &$v) {
+           $v = $v;
+}
+
+$arr = [$arr];
+
+var_dump(array_column($arr, 'name', 'id'));
+?>
+--EXPECT--
+array(1) {
+  [12345]=>
+  string(3) "sam"
+}