diff --git a/UPGRADING b/UPGRADING index 4a467d7e1c950..7525a3398b136 100644 --- a/UPGRADING +++ b/UPGRADING @@ -61,7 +61,7 @@ PHP 8.5 UPGRADE NOTES ======================================== - Zlib: - . The "use_include_path" argument for the + . The "use_include_path" argument for the gzfile, gzopen and readgzfile functions had been changed from int to boolean. @@ -83,6 +83,10 @@ PHP 8.5 UPGRADE NOTES statement from the DEALLOCATE sql command in that we can reuse its name afterwards. +- Standard: + . Added get_declared_enums() function that returns a list of declared enums. The + existing get_declared_classes() function continues to include enums. + ======================================== 7. New Classes and Interfaces ======================================== diff --git a/Zend/Optimizer/zend_func_infos.h b/Zend/Optimizer/zend_func_infos.h index 8751ff30c6950..97aff022682b3 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_enums", 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..2c1d08c60ee70 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1382,7 +1382,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 +1420,13 @@ ZEND_FUNCTION(get_declared_interfaces) } /* }}} */ +/* {{{ Returns an array of all declared enums. */ +ZEND_FUNCTION(get_declared_enums) +{ + get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED | ZEND_ACC_ENUM); +} +/* }}} */ + /* {{{ 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..4324d56e46819 100644 --- a/Zend/zend_builtin_functions.stub.php +++ b/Zend/zend_builtin_functions.stub.php @@ -140,6 +140,12 @@ function get_declared_traits(): array {} */ function get_declared_interfaces(): array {} +/** + * @return array + * @refcount 1 + */ +function get_declared_enums(): array {} + /** * @return array * @refcount 1 diff --git a/Zend/zend_builtin_functions_arginfo.h b/Zend/zend_builtin_functions_arginfo.h index cf34b1c0012d5..200ca3b522567 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: 3437a70925f1bb521ee264aba4a5b32af42c2f17 */ 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") @@ -160,6 +160,8 @@ ZEND_END_ARG_INFO() #define arginfo_get_declared_interfaces arginfo_func_get_args +#define arginfo_get_declared_enums 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() @@ -277,6 +279,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_enums); ZEND_FUNCTION(get_defined_functions); ZEND_FUNCTION(get_defined_vars); ZEND_FUNCTION(get_resource_type); @@ -341,6 +344,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_enums, arginfo_get_declared_enums) 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) diff --git a/ext/standard/tests/class_object/get_declared_enums_basic.phpt b/ext/standard/tests/class_object/get_declared_enums_basic.phpt new file mode 100644 index 0000000000000..78d3ee4d6f0d1 --- /dev/null +++ b/ext/standard/tests/class_object/get_declared_enums_basic.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test get_declared_enums() function +--FILE-- + +--EXPECTF-- +array(%d) { +%a +} +Ensure all enums are included. +bool(true) +bool(true) +bool(true) +bool(true) +Ensure interfaces are not included. +bool(true) +bool(true) +Ensure traits are not included. +bool(true) +Ensure classes are not included. +bool(true) +bool(true) +Ensure enums are included in get_declared_classes(). +bool(true) +bool(true) +bool(true) +bool(true) +Done