diff options
| author | Xinchen Hui <laruence@php.net> | 2015-03-25 23:42:58 +0800 |
|---|---|---|
| committer | Xinchen Hui <laruence@php.net> | 2015-03-25 23:50:54 +0800 |
| commit | d55d10c7fd7353bfc9e42e3d81bd61a87c063770 (patch) | |
| tree | 3e6981387047a5cf9982084723060bde5d3cc675 | |
| parent | 6aaee5fc1418decf049e3c3ab33b97b9d081c892 (diff) | |
| download | php-git-d55d10c7fd7353bfc9e42e3d81bd61a87c063770.tar.gz | |
Fixed bug #69299 (Regression in array_filter's $flag argument in PHP 7)
| -rw-r--r-- | NEWS | 2 | ||||
| -rw-r--r-- | ext/standard/array.c | 22 | ||||
| -rw-r--r-- | ext/standard/tests/array/bug69299.phpt | 18 |
3 files changed, 30 insertions, 12 deletions
@@ -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 cd6e020216..441d03fe1d 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 0000000000..088b10fd13 --- /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) { +} |
