com php-src: Fixed bug #70668 (array_keys() doesn't respect references when $strict is true): NEWS ext/standard/array.c
ext/standard/tests/array/bug7 0668.phpt
| From: | Dmitry Stogov | Date: | Thu, 08 Oct 2015 11:59:02 +0000 |
| Subject: | com php-src: Fixed bug #70668 (array_keys() doesn't respect references when $strict is true): NEWS ext/standard/array.c ext/standard/tests/array/bug7 0668.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89331@lists.php.net to get a copy of this message | ||
Commit: 3815e9713601a637b30bb99d631fc68df97f9288
Author: Dmitry Stogov <dmitry@zend.com> Thu, 8 Oct 2015 14:59:02 +0300
Parents: 9af07e7119a150acd5911c97da5d91fe9e424570
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3815e9713601a637b30bb99d631fc68df97f9288
Log:
Fixed bug #70668 (array_keys() doesn't respect references when $strict is true)
Bugs:
https://bugs.php.net/70668
Changed paths:
M NEWS
M ext/standard/array.c
A ext/standard/tests/array/bug70668.phpt
Diff:
diff --git a/NEWS b/NEWS
index 6e0b58f..44adba2 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,9 @@ PHP NEWS
- Standard:
. Fixed bug #70667 (strtr() causes invalid writes and a crashes). (Dmitry)
+ . Fixed bug #70668 (array_keys() doesn't respect references when $strict is
+ true). (Bob, Dmitry)
+
01 Oct 2015, PHP 7.0.0 RC 4
diff --git a/ext/standard/array.c b/ext/standard/array.c
index b9d39ea..4678e14 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -3282,6 +3282,7 @@ PHP_FUNCTION(array_keys)
if (strict) {
ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(input), num_idx, str_idx, entry) {
+ ZVAL_DEREF(entry);
if (fast_is_identical_function(search_value, entry)) {
if (str_idx) {
ZVAL_STR_COPY(&new_val, str_idx);
diff --git a/ext/standard/tests/array/bug70668.phpt b/ext/standard/tests/array/bug70668.phpt
new file mode 100644
index 0000000..b35107a
--- /dev/null
+++ b/ext/standard/tests/array/bug70668.phpt
@@ -0,0 +1,63 @@
+--TEST--
+Bug #70668 (array_keys() doesn't respect references when $strict is true)
+--FILE--
+<?php
+$arr = array(1, "1", "", NULL, 0, false, true, array());
+
+$s = &$arr[0];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[1];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[2];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[3];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[4];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[5];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[6];
+var_dump(array_keys($arr, $s, true));
+
+$s = &$arr[7];
+var_dump(array_keys($arr, $s, true));
+?>
+--EXPECT--
+array(1) {
+ [0]=>
+ int(0)
+}
+array(1) {
+ [0]=>
+ int(1)
+}
+array(1) {
+ [0]=>
+ int(2)
+}
+array(1) {
+ [0]=>
+ int(3)
+}
+array(1) {
+ [0]=>
+ int(4)
+}
+array(1) {
+ [0]=>
+ int(5)
+}
+array(1) {
+ [0]=>
+ int(6)
+}
+array(1) {
+ [0]=>
+ int(7)
+}