From d99b3b842c619ba8a54e355dee0bf6140bebad4d Mon Sep 17 00:00:00 2001 From: DanielEScherzer Date: Thu, 6 Feb 2025 17:58:38 -0800 Subject: [PATCH 1/2] reflection: try to avoid manual string comparison In `is_closure_invoke()` compare with the well known zend_string `ZEND_STR_MAGIC_INVOKE` rather than the underlying literal value. --- ext/reflection/php_reflection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 724de0a491240..07a38b2d3d640 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -194,7 +194,7 @@ static zend_always_inline uint32_t prop_get_flags(const property_reference *ref) static inline bool is_closure_invoke(const zend_class_entry *ce, const zend_string *lcname) { return ce == zend_ce_closure - && zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME); + && zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE)); } static zend_function *_copy_function(zend_function *fptr) /* {{{ */ From 86b54b0666746085c591811557f89ffe0b317447 Mon Sep 17 00:00:00 2001 From: Daniel Scherzer Date: Wed, 12 Feb 2025 18:06:57 -0800 Subject: [PATCH 2/2] builtin functions: try to avoid manual string comparison Make use of the well known zend_string objects `ZEND_STR_MAGIC_INVOKE` and `ZEND_STR_UNKNOWN_CAPITALIZED` --- Zend/zend_builtin_functions.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index bb8bb28bf6e4f..daf39ba5c68b6 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -974,7 +974,7 @@ ZEND_FUNCTION(method_exists) if (func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) { /* Returns true for the fake Closure's __invoke */ RETVAL_BOOL(func->common.scope == zend_ce_closure - && zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME)); + && zend_string_equals_ci(method_name, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))); zend_string_release_ex(func->common.function_name, 0); zend_free_trampoline(func); @@ -985,7 +985,7 @@ ZEND_FUNCTION(method_exists) } else { /* Returns true for fake Closure::__invoke */ if (ce == zend_ce_closure - && zend_string_equals_literal_ci(method_name, ZEND_INVOKE_FUNC_NAME)) { + && zend_string_equals_ci(method_name, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE))) { RETURN_TRUE; } } @@ -1537,7 +1537,7 @@ ZEND_FUNCTION(get_resources) zend_hash_index_add_new(Z_ARRVAL_P(return_value), index, val); } } ZEND_HASH_FOREACH_END(); - } else if (zend_string_equals_literal(type, "Unknown")) { + } else if (zend_string_equals(type, ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED))) { array_init(return_value); ZEND_HASH_FOREACH_KEY_VAL(&EG(regular_list), index, key, val) { if (!key && Z_RES_TYPE_P(val) <= 0) {