From: Máté Kocsis Date: Sun, 3 May 2020 11:19:44 +0000 (+0200) Subject: Fix UNKNOWN default values in ext/spl X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=650da66e2dbd5e20f956c225b4a5d423fb18ccbe;p=php Fix UNKNOWN default values in ext/spl --- diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 11fec69072..b6b04cb269 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -310,12 +310,16 @@ PHP_FUNCTION(spl_autoload) { int pos_len, pos1_len; char *pos, *pos1; - zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); + zend_string *class_name, *lc_name, *file_exts = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &class_name, &file_exts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!", &class_name, &file_exts) == FAILURE) { RETURN_THROWS(); } + if (!file_exts) { + file_exts = SPL_G(autoload_extensions); + } + if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */ pos = SPL_DEFAULT_FILE_EXTENSIONS; pos_len = sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1; @@ -347,9 +351,10 @@ PHP_FUNCTION(spl_autoload_extensions) { zend_string *file_exts = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &file_exts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &file_exts) == FAILURE) { RETURN_THROWS(); } + if (file_exts) { if (SPL_G(autoload_extensions)) { zend_string_release_ex(SPL_G(autoload_extensions), 0); @@ -513,11 +518,11 @@ PHP_FUNCTION(spl_autoload_register) zend_object *obj_ptr; zend_fcall_info_cache fcc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z!bb", &zcallable, &do_throw, &prepend) == FAILURE) { RETURN_THROWS(); } - if (ZEND_NUM_ARGS()) { + if (zcallable) { if (!zend_is_callable_ex(zcallable, NULL, 0, &func_name, &fcc, &error)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; diff --git a/ext/spl/php_spl.stub.php b/ext/spl/php_spl.stub.php index 8811e1913a..8e2a6edf0a 100755 --- a/ext/spl/php_spl.stub.php +++ b/ext/spl/php_spl.stub.php @@ -8,16 +8,16 @@ function class_parents($instance, bool $autoload = true): array|false {} function class_uses($what, bool $autoload = true): array|false {} -function spl_autoload(string $class_name, string $file_extensions = UNKNOWN): void {} +function spl_autoload(string $class_name, ?string $file_extensions = null): void {} // This silently ignores non-string class names function spl_autoload_call($class_name): void {} -function spl_autoload_extensions(string $file_extensions = UNKNOWN): string {} +function spl_autoload_extensions(?string $file_extensions = null): string {} function spl_autoload_functions(): array|false {} -function spl_autoload_register($autoload_function = UNKNOWN, bool $throw = true, bool $prepend = false): bool {} +function spl_autoload_register($autoload_function = null, bool $throw = true, bool $prepend = false): bool {} function spl_autoload_unregister($autoload_function): bool {} diff --git a/ext/spl/php_spl_arginfo.h b/ext/spl/php_spl_arginfo.h index 0b19431fd4..f02c9d22e3 100644 --- a/ext/spl/php_spl_arginfo.h +++ b/ext/spl/php_spl_arginfo.h @@ -14,7 +14,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, file_extensions, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_extensions, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_call, 0, 1, IS_VOID, 0) @@ -22,14 +22,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_call, 0, 1, IS_VOID ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, file_extensions, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_extensions, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_spl_autoload_functions, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_register, 0, 0, _IS_BOOL, 0) - ZEND_ARG_INFO(0, autoload_function) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, autoload_function, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, throw, _IS_BOOL, 0, "true") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prepend, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO()