From: Xinchen Hui Date: Thu, 25 Feb 2016 08:07:22 +0000 (+0800) Subject: Fixed bug #71660 (array_column behaves incorrectly after foreach by reference) X-Git-Tag: php-7.0.5RC1~58 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c299b272c77b9bea4d6371a37a6d2b894f9729e8;p=php Fixed bug #71660 (array_column behaves incorrectly after foreach by reference) --- diff --git a/NEWS b/NEWS index 27dfe73832..a7c80bd25c 100644 --- 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) diff --git a/ext/standard/array.c b/ext/standard/array.c index 5add302c46..def7d7c465 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -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 index 0000000000..c2d7192378 --- /dev/null +++ b/ext/standard/tests/array/bug71660.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #71660 (array_column behaves incorrectly after foreach by reference) +--FILE-- + 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" +}