com php-src: Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7): NEWS ext/stand ard/array.c ext/standard/tests/array/bug69299.p
hpt

From: Date: Wed, 25 Mar 2015 15:50:54 +0000
Subject: com php-src: Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7): NEWS ext/stand ard/array.c ext/standard/tests/array/bug69299.p
hpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85874@lists.php.net to get a copy of this message
Commit: d55d10c7fd7353bfc9e42e3d81bd61a87c063770 Author: Xinchen Hui <laruence@php.net> Wed, 25 Mar 2015 23:42:58 +0800 Parents: 6aaee5fc1418decf049e3c3ab33b97b9d081c892 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d55d10c7fd7353bfc9e42e3d81bd61a87c063770 Log: Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7) Bugs: https://bugs.php.net/69299 Changed paths: M NEWS M ext/standard/array.c A ext/standard/tests/array/bug69299.phpt Diff: diff --git a/NEWS b/NEWS index 09e8852..d9bbac2 100644 --- a/NEWS +++ b/NEWS @@ -161,6 +161,8 @@ 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) diff --git a/ext/standard/array.c b/ext/standard/array.c index cd6e020..441d03f 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -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 index 0000000...088b10f --- /dev/null +++ b/ext/standard/tests/array/bug69299.phpt @@ -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) { +}

« previous php.cvs (#85874) next »