Skip to content

Commit da9b2a0

Browse files
committed
Add symbol_exists
1 parent 55e8ebe commit da9b2a0

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

Zend/Optimizer/zend_func_infos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static const func_info_t func_infos[] = {
1111
F1("get_declared_classes", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1212
F1("get_declared_traits", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1313
F1("get_declared_interfaces", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
14+
F1("get_declared_symbols", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING),
1415
F1("get_defined_functions", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ARRAY),
1516
F1("get_defined_vars", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF),
1617
F1("get_resource_type", MAY_BE_STRING),

Zend/zend_builtin_functions.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,6 +1157,11 @@ ZEND_FUNCTION(enum_exists)
11571157
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_ENUM, 0);
11581158
}
11591159

1160+
ZEND_FUNCTION(symbol_exists)
1161+
{
1162+
class_exists_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED, 0);
1163+
}
1164+
11601165
/* {{{ Checks if the function exists */
11611166
ZEND_FUNCTION(function_exists)
11621167
{
@@ -1382,7 +1387,7 @@ static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int fla
13821387
ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) {
13831388
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(EG(class_table), key, zv) {
13841389
ce = Z_PTR_P(zv);
1385-
if ((ce->ce_flags & (ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT)) == flags
1390+
if ((ce->ce_flags & (flags|ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT)) == flags
13861391
&& key
13871392
&& ZSTR_VAL(key)[0] != 0) {
13881393
ZEND_HASH_FILL_GROW();
@@ -1420,6 +1425,13 @@ ZEND_FUNCTION(get_declared_interfaces)
14201425
}
14211426
/* }}} */
14221427

1428+
/* {{{ Returns an array of all declared symbols. */
1429+
ZEND_FUNCTION(get_declared_symbols)
1430+
{
1431+
get_declared_class_impl(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_LINKED|ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT);
1432+
}
1433+
/* }}} */
1434+
14231435
/* {{{ Returns an array of all defined functions */
14241436
ZEND_FUNCTION(get_defined_functions)
14251437
{

Zend/zend_builtin_functions.stub.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ function trait_exists(string $trait, bool $autoload = true): bool {}
9191

9292
function enum_exists(string $enum, bool $autoload = true): bool {}
9393

94+
function symbol_exists(string $symbol, bool $autoload = true): bool {}
95+
9496
function function_exists(string $function): bool {}
9597

9698
function class_alias(string $class, string $alias, bool $autoload = true): bool {}
@@ -140,6 +142,12 @@ function get_declared_traits(): array {}
140142
*/
141143
function get_declared_interfaces(): array {}
142144

145+
/**
146+
* @return array<int, string>
147+
* @refcount 1
148+
*/
149+
function get_declared_symbols(): array {}
150+
143151
/**
144152
* @return array<string, array>
145153
* @refcount 1

Zend/zend_builtin_functions_arginfo.h

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)