]> granicus.if.org Git - php/commitdiff
Allow null callback to array_filter()
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 13 May 2020 15:24:13 +0000 (17:24 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 13 May 2020 15:24:13 +0000 (17:24 +0200)
With same behavior as not passing it.

Zend/zend_API.h
ext/libxml/libxml.c
ext/sqlite3/sqlite3.c
ext/standard/array.c
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/tests/array/array_filter_basic.phpt

index c3554568923152b26b95c1e3b31cf670d37af7e2..3943f691bff9fca4ec345e583265ffe093a1ce42 100644 (file)
@@ -1380,6 +1380,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_value_error(uint32_t arg_num
 #define Z_PARAM_FUNC(dest_fci, dest_fcc) \
        Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 0, 0)
 
+#define Z_PARAM_FUNC_OR_NULL(dest_fci, dest_fcc) \
+       Z_PARAM_FUNC_EX(dest_fci, dest_fcc, 1, 0)
+
 /* old "h" */
 #define Z_PARAM_ARRAY_HT_EX2(dest, check_null, deref, separate) \
                Z_PARAM_PROLOGUE(deref, separate); \
index febc5eca2daaf2376cbb58918d287a4b8abdf039..09f8ae83ed93cda63194292b6878e7e399f9e17a 100644 (file)
@@ -1067,7 +1067,7 @@ PHP_FUNCTION(libxml_set_external_entity_loader)
        zend_fcall_info_cache   fcc;
 
        ZEND_PARSE_PARAMETERS_START(1, 1)
-               Z_PARAM_FUNC_EX(fci, fcc, 1, 0)
+               Z_PARAM_FUNC_OR_NULL(fci, fcc)
        ZEND_PARSE_PARAMETERS_END();
 
        _php_libxml_destroy_fci(&LIBXML(entity_loader).fci, &LIBXML(entity_loader).object);
index b978c49d80431de4d7d94d01540cfa8bbe6578f4..2a36ffd5d47e188e36fdef800527efb285926c33 100644 (file)
@@ -1361,7 +1361,7 @@ PHP_METHOD(SQLite3, setAuthorizer)
        zend_fcall_info_cache   fcc;
 
        ZEND_PARSE_PARAMETERS_START(1, 1)
-               Z_PARAM_FUNC_EX(fci, fcc, 1, 0)
+               Z_PARAM_FUNC_OR_NULL(fci, fcc)
        ZEND_PARSE_PARAMETERS_END();
 
        SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)
index fd0ceaa6006cf19fc618879fb9ca58f5418e5501..51386148588edd92e6b952dfd5256ababa5f6d09 100644 (file)
@@ -5958,7 +5958,7 @@ PHP_FUNCTION(array_filter)
        ZEND_PARSE_PARAMETERS_START(1, 3)
                Z_PARAM_ARRAY(array)
                Z_PARAM_OPTIONAL
-               Z_PARAM_FUNC(fci, fci_cache)
+               Z_PARAM_FUNC_OR_NULL(fci, fci_cache)
                Z_PARAM_LONG(use_type)
        ZEND_PARSE_PARAMETERS_END();
 
@@ -5969,7 +5969,7 @@ PHP_FUNCTION(array_filter)
        }
        array_init(return_value);
 
-       if (ZEND_NUM_ARGS() > 1) {
+       if (ZEND_FCI_INITIALIZED(fci)) {
                have_callback = 1;
                fci.no_separation = 0;
                fci.retval = &retval;
@@ -6045,7 +6045,7 @@ PHP_FUNCTION(array_map)
        uint32_t k, maxlen = 0;
 
        ZEND_PARSE_PARAMETERS_START(2, -1)
-               Z_PARAM_FUNC_EX(fci, fci_cache, 1, 0)
+               Z_PARAM_FUNC_OR_NULL(fci, fci_cache)
                Z_PARAM_VARIADIC('+', arrays, n_arrays)
        ZEND_PARSE_PARAMETERS_END();
 
index 2017549e9b55a4465afd5c1b92b7509aa8525ecf..71b922d7b2e2796fd73a7ff1de96eb5dd7bfa7c8 100755 (executable)
@@ -237,7 +237,7 @@ function array_product(array $arg): int|float {}
 /** @return mixed */
 function array_reduce(array $arg, callable $callback, $initial = null) {}
 
-function array_filter(array $arg, callable $callback = UNKNOWN, int $use_keys = 0): array {}
+function array_filter(array $arg, ?callable $callback = null, int $use_keys = 0): array {}
 
 function array_map(?callable $callback, array $arr1, array ...$arrays): array {}
 
index 5e2e457ea286e1bc8a682cbba5c1f28e4552f6f1..23152bc22eac9d3adca6bfb35a4a2bd934bfdcc7 100755 (executable)
@@ -338,7 +338,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_filter, 0, 1, IS_ARRAY, 0)
        ZEND_ARG_TYPE_INFO(0, arg, IS_ARRAY, 0)
-       ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, callback, IS_CALLABLE, 1, "null")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, use_keys, IS_LONG, 0, "0")
 ZEND_END_ARG_INFO()
 
index b2a51ab2c60c3f346edce226fad3bf0885248382..1b686495464eb879bdc9afdd00f482187ddd5acd 100644 (file)
@@ -31,6 +31,8 @@ var_dump( array_filter($input,"even") );
 
 // with default arguments
 var_dump( array_filter($input) );
+// same as with default arguments
+var_dump( array_filter($input, null) );
 
 echo "Done"
 ?>
@@ -52,4 +54,14 @@ array(4) {
   [4]=>
   int(-1)
 }
+array(4) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+  [4]=>
+  int(-1)
+}
 Done