From da9b2a0cd68f802c1f4ed035972cb2cc3abc8f2a Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Sun, 13 Oct 2024 20:25:51 +0700 Subject: [PATCH] Add symbol_exists --- Zend/Optimizer/zend_func_infos.h | 1 + Zend/zend_builtin_functions.c | 14 +++++++++++++- Zend/zend_builtin_functions.stub.php | 8 ++++++++ Zend/zend_builtin_functions_arginfo.h | 13 ++++++++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h index 8751ff30c6950..7458020935100 100644 --- a/Zend/Optimizer/zend_func_infos.h +++ b/Zend/Optimizer/zend_func_infos.h @@ -11,6 +11,7 @@ static const func_info_t func_infos[] = { F1("get_declared_classes", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), F1("get_declared_traits", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), F1("get_declared_interfaces", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), + F1("get_declared_symbols", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING), F1("get_defined_functions", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ARRAY), F1("get_defined_vars", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF), F1("get_resource_type", MAY_BE_STRING), diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index bb8bb28bf6e4f..9b42c2032a9d4 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1157,6 +1157,11 @@ ZEND_FUNCTION(enum_exists) class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_ENUM, 0); } +ZEND_FUNCTION(symbol_exists) +{ + class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, 0); +} + /* {{{ Checks if the function exists */ ZEND_FUNCTION(function_exists) { @@ -1382,7 +1387,7 @@ static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int fla ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) { ce = Z_PTR_P(zv); - if ((ce->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT)) == flags + if ((ce->ce_flags & (flags|ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT)) == flags && key && ZSTR_VAL(key)[0] != 0) { ZEND_HASH_FILL_GROW(); @@ -1420,6 +1425,13 @@ ZEND_FUNCTION(get_declared_interfaces) } /* }}} */ +/* {{{ Returns an array of all declared symbols. */ +ZEND_FUNCTION(get_declared_symbols) +{ + get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT); +} +/* }}} */ + /* {{{ Returns an array of all defined functions */ ZEND_FUNCTION(get_defined_functions) { diff --git a/Zend/zend_builtin_functions.stub.php b/Zend/zend_builtin_functions.stub.php index f7009c4ffba6e..e19ef91be2b28 100644 --- a/Zend/zend_builtin_functions.stub.php +++ b/Zend/zend_builtin_functions.stub.php @@ -91,6 +91,8 @@ function trait_exists(string $trait, bool $autoload = true): bool {} function enum_exists(string $enum, bool $autoload = true): bool {} +function symbol_exists(string $symbol, bool $autoload = true): bool {} + function function_exists(string $function): bool {} function class_alias(string $class, string $alias, bool $autoload = true): bool {} @@ -140,6 +142,12 @@ function get_declared_traits(): array {} */ function get_declared_interfaces(): array {} +/** + * @return array + * @refcount 1 + */ +function get_declared_symbols(): array {} + /** * @return array * @refcount 1 diff --git a/Zend/zend_builtin_functions_arginfo.h b/Zend/zend_builtin_functions_arginfo.h index cf34b1c0012d5..cb628ff3063fe 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: 3dbc84896823c9aaa9ac8aeef8841266920c3e50 */ + * Stub hash: 1140e967f646633613a1640f2e16c99231830b48 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_exit, 0, 0, IS_NEVER, 0) ZEND_ARG_TYPE_MASK(0, status, MAY_BE_STRING|MAY_BE_LONG, "0") @@ -119,6 +119,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enum_exists, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, autoload, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_symbol_exists, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, symbol, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, autoload, _IS_BOOL, 0, "true") +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_function_exists, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, function, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -160,6 +165,8 @@ ZEND_END_ARG_INFO() #define arginfo_get_declared_interfaces arginfo_func_get_args +#define arginfo_get_declared_symbols arginfo_func_get_args + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_defined_functions, 0, 0, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, exclude_disabled, _IS_BOOL, 0, "true") ZEND_END_ARG_INFO() @@ -266,6 +273,7 @@ ZEND_FUNCTION(class_exists); ZEND_FUNCTION(interface_exists); ZEND_FUNCTION(trait_exists); ZEND_FUNCTION(enum_exists); +ZEND_FUNCTION(symbol_exists); ZEND_FUNCTION(function_exists); ZEND_FUNCTION(class_alias); ZEND_FUNCTION(get_included_files); @@ -277,6 +285,7 @@ ZEND_FUNCTION(restore_exception_handler); ZEND_FUNCTION(get_declared_classes); ZEND_FUNCTION(get_declared_traits); ZEND_FUNCTION(get_declared_interfaces); +ZEND_FUNCTION(get_declared_symbols); ZEND_FUNCTION(get_defined_functions); ZEND_FUNCTION(get_defined_vars); ZEND_FUNCTION(get_resource_type); @@ -328,6 +337,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(interface_exists, arginfo_interface_exists) ZEND_FE(trait_exists, arginfo_trait_exists) ZEND_FE(enum_exists, arginfo_enum_exists) + ZEND_FE(symbol_exists, arginfo_symbol_exists) ZEND_FE(function_exists, arginfo_function_exists) ZEND_FE(class_alias, arginfo_class_alias) ZEND_FE(get_included_files, arginfo_get_included_files) @@ -341,6 +351,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(get_declared_classes, arginfo_get_declared_classes) ZEND_FE(get_declared_traits, arginfo_get_declared_traits) ZEND_FE(get_declared_interfaces, arginfo_get_declared_interfaces) + ZEND_FE(get_declared_symbols, arginfo_get_declared_symbols) ZEND_FE(get_defined_functions, arginfo_get_defined_functions) ZEND_FE(get_defined_vars, arginfo_get_defined_vars) ZEND_FE(get_resource_type, arginfo_get_resource_type)