Skip to content

Commit 50a9f51

Browse files
committed
Allow null callback to array_filter()
With same behavior as not passing it.
1 parent 9122638 commit 50a9f51

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

Zend/zend_API.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
13801380
#define Z_PARAM_FUNC(dest_fci, dest_fcc) \
13811381
Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
13821382

1383+
#define Z_PARAM_FUNC_OR_NULL(dest_fci, dest_fcc) \
1384+
Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 1, 0)
1385+
13831386
/* old "h" */
13841387
#define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
13851388
Z_PARAM_PROLOGUE(deref, separate); \

ext/libxml/libxml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ PHP_FUNCTION(libxml_set_external_entity_loader)
10671067
zend_fcall_info_cache fcc;
10681068

10691069
ZEND_PARSE_PARAMETERS_START(1, 1)
1070-
Z_PARAM_FUNC_EX(fci, fcc, 1, 0)
1070+
Z_PARAM_FUNC_OR_NULL(fci, fcc)
10711071
ZEND_PARSE_PARAMETERS_END();
10721072

10731073
_php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object);

ext/sqlite3/sqlite3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ PHP_METHOD(SQLite3, setAuthorizer)
13611361
zend_fcall_info_cache fcc;
13621362

13631363
ZEND_PARSE_PARAMETERS_START(1, 1)
1364-
Z_PARAM_FUNC_EX(fci, fcc, 1, 0)
1364+
Z_PARAM_FUNC_OR_NULL(fci, fcc)
13651365
ZEND_PARSE_PARAMETERS_END();
13661366

13671367
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)

ext/standard/array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5958,7 +5958,7 @@ PHP_FUNCTION(array_filter)
59585958
ZEND_PARSE_PARAMETERS_START(1, 3)
59595959
Z_PARAM_ARRAY(array)
59605960
Z_PARAM_OPTIONAL
5961-
Z_PARAM_FUNC(fci, fci_cache)
5961+
Z_PARAM_FUNC_OR_NULL(fci, fci_cache)
59625962
Z_PARAM_LONG(use_type)
59635963
ZEND_PARSE_PARAMETERS_END();
59645964

@@ -5969,7 +5969,7 @@ PHP_FUNCTION(array_filter)
59695969
}
59705970
array_init(return_value);
59715971

5972-
if (ZEND_NUM_ARGS() > 1) {
5972+
if (ZEND_FCI_INITIALIZED(fci)) {
59735973
have_callback = 1;
59745974
fci.no_separation = 0;
59755975
fci.retval = &retval;
@@ -6045,7 +6045,7 @@ PHP_FUNCTION(array_map)
60456045
uint32_t k, maxlen = 0;
60466046

60476047
ZEND_PARSE_PARAMETERS_START(2, -1)
6048-
Z_PARAM_FUNC_EX(fci, fci_cache, 1, 0)
6048+
Z_PARAM_FUNC_OR_NULL(fci, fci_cache)
60496049
Z_PARAM_VARIADIC('+', arrays, n_arrays)
60506050
ZEND_PARSE_PARAMETERS_END();
60516051

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function array_product(array $arg): int|float {}
237237
/** @return mixed */
238238
function array_reduce(array $arg, callable $callback, $initial = null) {}
239239

240-
function array_filter(array $arg, callable $callback = UNKNOWN, int $use_keys = 0): array {}
240+
function array_filter(array $arg, ?callable $callback = null, int $use_keys = 0): array {}
241241

242242
function array_map(?callable $callback, array $arr1, array ...$arrays): array {}
243243

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ ZEND_END_ARG_INFO()
338338

339339
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_filter, 0, 1, IS_ARRAY, 0)
340340
ZEND_ARG_TYPE_INFO(0, arg, IS_ARRAY, 0)
341-
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
341+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callback, IS_CALLABLE, 1, "null")
342342
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_keys, IS_LONG, 0, "0")
343343
ZEND_END_ARG_INFO()
344344

ext/standard/tests/array/array_filter_basic.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ var_dump( array_filter($input,"even") );
3131

3232
// with default arguments
3333
var_dump( array_filter($input) );
34+
// same as with default arguments
35+
var_dump( array_filter($input, null) );
3436

3537
echo "Done"
3638
?>
@@ -52,4 +54,14 @@ array(4) {
5254
[4]=>
5355
int(-1)
5456
}
57+
array(4) {
58+
[0]=>
59+
int(1)
60+
[1]=>
61+
int(2)
62+
[2]=>
63+
int(3)
64+
[4]=>
65+
int(-1)
66+
}
5567
Done

0 commit comments

Comments
 (0)