]> granicus.if.org Git - php/commitdiff
Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7)
authorXinchen Hui <laruence@php.net>
Wed, 25 Mar 2015 15:42:58 +0000 (23:42 +0800)
committerXinchen Hui <laruence@php.net>
Wed, 25 Mar 2015 15:50:54 +0000 (23:50 +0800)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug69299.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 09e88523f87776fa4986c6dfe2a927ee7128111c..d9bbac2391a98f0e1cbe22ed556b338645df9d91 100644 (file)
--- a/NEWS
+++ b/NEWS
     required_num_args). (Julien)
 
 - Standard:
+  . Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7).
+    (Laruence)
   . Removed call_user_method() and call_user_method_array() functions. (Kalle)
   . Fixed user session handlers (See rfc:session.user.return-value). (Sara)
   . Added intdiv() function. (Andrea)
index cd6e0202163b340cc664a08bdb03a32fafc1a5e0..441d03fe1deba26516f5d91c32b756423d1f2245 100644 (file)
@@ -4744,6 +4744,7 @@ PHP_FUNCTION(array_filter)
 {
        zval *array;
        zval *operand;
+       zval *key;
        zval args[2];
        zval retval;
        zend_bool have_callback = 0;
@@ -4766,7 +4767,13 @@ PHP_FUNCTION(array_filter)
                have_callback = 1;
                fci.no_separation = 0;
                fci.retval = &retval;
-               fci.param_count = 1;
+               if (use_type == ARRAY_FILTER_USE_BOTH) {
+                       fci.param_count = 2;
+                       key = &args[1];
+               } else {
+                       fci.param_count = 1;
+                       key = &args[0];
+               }
        }
 
        ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) {
@@ -4774,18 +4781,9 @@ PHP_FUNCTION(array_filter)
                        if (use_type) {
                                /* Set up the key */
                                if (!string_key) {
-                                       if (use_type == ARRAY_FILTER_USE_BOTH) {
-                                               fci.param_count = 2;
-                                               ZVAL_LONG(&args[1], num_key);
-                                       } else if (use_type == ARRAY_FILTER_USE_KEY) {
-                                               ZVAL_LONG(&args[0], num_key);
-                                       }
+                                       ZVAL_LONG(key, num_key);
                                } else {
-                                       if (use_type == ARRAY_FILTER_USE_BOTH) {
-                                               ZVAL_STR_COPY(&args[1], string_key);
-                                       } else if (use_type == ARRAY_FILTER_USE_KEY) {
-                                               ZVAL_STR_COPY(&args[0], string_key);
-                                       }
+                                       ZVAL_STR_COPY(key, string_key);
                                }
                        }
                        if (use_type != ARRAY_FILTER_USE_KEY) {
diff --git a/ext/standard/tests/array/bug69299.phpt b/ext/standard/tests/array/bug69299.phpt
new file mode 100644 (file)
index 0000000..088b10f
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #69299 (Regression in array_filter's $flag argument in PHP 7)
+--FILE--
+<?php
+$toFilter = array('foo' => 'bar', 'fiz' => 'buz');
+$filtered = array_filter($toFilter, function ($value, $key) {
+       if ($value === 'buz'
+               || $key === 'foo'
+       ) {
+               return false;
+       }
+       return true;
+}, ARRAY_FILTER_USE_BOTH);
+var_dump($filtered);
+?>
+--EXPECT--
+array(0) {
+}