From 12d087c346592473a4e67e935a892e5f19de88b5 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 22 Sep 2020 13:05:05 +0200 Subject: [PATCH] Use C zpp for get_class_vars() --- Zend/tests/get_class_vars_001.phpt | 7 +++++++ Zend/zend_builtin_functions.c | 25 ++++++++++--------------- Zend/zend_builtin_functions.stub.php | 2 +- Zend/zend_builtin_functions_arginfo.h | 4 ++-- ext/opcache/Optimizer/zend_func_info.c | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Zend/tests/get_class_vars_001.phpt b/Zend/tests/get_class_vars_001.phpt index a5939ccd5f..84f502610e 100644 --- a/Zend/tests/get_class_vars_001.phpt +++ b/Zend/tests/get_class_vars_001.phpt @@ -19,6 +19,12 @@ class B extends A { var_dump(get_class_vars('A')); var_dump(get_class_vars('B')); +try { + get_class_vars("Unknown"); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + ?> --EXPECT-- array(1) { @@ -31,3 +37,4 @@ array(2) { ["aa"]=> int(4) } +get_class_vars(): Argument #1 ($class) must be a valid class name, Unknown given diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index fbc7d13329..ac652b3b8a 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -747,27 +747,22 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, bool s /* {{{ Returns an array of default properties of the class. */ ZEND_FUNCTION(get_class_vars) { - zend_string *class_name; - zend_class_entry *ce, *scope; + zend_class_entry *ce = NULL, *scope; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &class_name) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "C", &ce) == FAILURE) { RETURN_THROWS(); } - ce = zend_lookup_class(class_name); - if (!ce) { - RETURN_FALSE; - } else { - array_init(return_value); - if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) { - if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { - return; - } + array_init(return_value); + if (UNEXPECTED(!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) { + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + return; } - scope = zend_get_executed_scope(); - add_class_vars(scope, ce, 0, return_value); - add_class_vars(scope, ce, 1, return_value); } + + scope = zend_get_executed_scope(); + add_class_vars(scope, ce, 0, return_value); + add_class_vars(scope, ce, 1, return_value); } /* }}} */ diff --git a/Zend/zend_builtin_functions.stub.php b/Zend/zend_builtin_functions.stub.php index 5d5ebcde14..eaf2ac490a 100644 --- a/Zend/zend_builtin_functions.stub.php +++ b/Zend/zend_builtin_functions.stub.php @@ -39,7 +39,7 @@ function is_subclass_of(mixed $object_or_class, string $class, bool $allow_strin /** @param object|string $object_or_class */ function is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool {} -function get_class_vars(string $class): array|false {} +function get_class_vars(string $class): array {} function get_object_vars(object $object): array {} diff --git a/Zend/zend_builtin_functions_arginfo.h b/Zend/zend_builtin_functions_arginfo.h index 4b551e3d59..d10e2c3d68 100644 --- a/Zend/zend_builtin_functions_arginfo.h +++ b/Zend/zend_builtin_functions_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 1f644f72600eddbbb01a4c3912a2c9c5fe12188e */ + * Stub hash: fed3b572fbcae7bda87efc377b56e027da12b511 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -69,7 +69,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_is_a, 0, 2, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, allow_string, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_class_vars, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_class_vars, 0, 1, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, class, IS_STRING, 0) ZEND_END_ARG_INFO() diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index e3a2588028..936e8a8915 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -97,7 +97,7 @@ static const func_info_t func_infos[] = { F1("zend_version", MAY_BE_STRING), FN("func_get_arg", UNKNOWN_INFO), FN("func_get_args", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_ANY), - F1("get_class_vars", MAY_BE_FALSE | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF), + F1("get_class_vars", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF), F1("get_class_methods", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), F1("get_included_files", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), FN("set_error_handler", MAY_BE_NULL | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_OBJECT | MAY_BE_OBJECT), -- 2.40.0