Skip to content

Use new known "self" and "parent" zend_strings #17766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,8 +2088,8 @@ ZEND_API void zend_alloc_ce_cache(zend_string *type_name)
return;
}

if (zend_string_equals_literal_ci(type_name, "self")
|| zend_string_equals_literal_ci(type_name, "parent")) {
if (zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_SELF))
|| zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -3760,7 +3760,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
zend_str_tolower_copy(ZSTR_VAL(lcname), ZSTR_VAL(name), name_len);

*strict_class = 0;
if (zend_string_equals_literal(lcname, "self")) {
if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_SELF))) {
if (!scope) {
if (error) *error = estrdup("cannot access \"self\" when no class scope is active");
} else {
Expand All @@ -3777,7 +3777,7 @@ static bool zend_is_callable_check_class(zend_string *name, zend_class_entry *sc
}
ret = 1;
}
} else if (zend_string_equals_literal(lcname, "parent")) {
} else if (zend_string_equals(lcname, ZSTR_KNOWN(ZEND_STR_PARENT))) {
if (!scope) {
if (error) *error = estrdup("cannot access \"parent\" when no class scope is active");
} else if (!scope->parent) {
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2257,10 +2257,10 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
/* The const expr representation stores the fetch type instead. */
switch (ast->attr) {
case ZEND_FETCH_CLASS_SELF:
smart_str_appends(str, "self");
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_SELF));
break;
case ZEND_FETCH_CLASS_PARENT:
smart_str_appends(str, "parent");
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_PARENT));
break;
EMPTY_SWITCH_DEFAULT_CASE()
}
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,9 @@ static zend_string *add_type_string(zend_string *type, zend_string *new_type, bo

static zend_string *resolve_class_name(zend_string *name, zend_class_entry *scope) {
if (scope) {
if (zend_string_equals_literal_ci(name, "self")) {
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) {
name = scope->name;
} else if (zend_string_equals_literal_ci(name, "parent") && scope->parent) {
} else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT)) && scope->parent) {
name = scope->parent->name;
}
}
Expand Down Expand Up @@ -1730,9 +1730,9 @@ static inline bool class_name_refers_to_active_ce(zend_string *class_name, uint3

uint32_t zend_get_class_fetch_type(const zend_string *name) /* {{{ */
{
if (zend_string_equals_literal_ci(name, "self")) {
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) {
return ZEND_FETCH_CLASS_SELF;
} else if (zend_string_equals_literal_ci(name, "parent")) {
} else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
return ZEND_FETCH_CLASS_PARENT;
} else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_STATIC))) {
return ZEND_FETCH_CLASS_STATIC;
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ ZEND_API zval *zend_get_class_constant_ex(zend_string *class_name, zend_string *
if (!ce) {
ce = zend_fetch_class(class_name, flags);
}
} else if (zend_string_equals_literal_ci(class_name, "self")) {
} else if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_SELF))) {
if (UNEXPECTED(!scope)) {
zend_throw_error(NULL, "Cannot access \"self\" when no class scope is active");
goto failure;
}
ce = scope;
} else if (zend_string_equals_literal_ci(class_name, "parent")) {
} else if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
if (UNEXPECTED(!scope)) {
zend_throw_error(NULL, "Cannot access \"parent\" when no class scope is active");
goto failure;
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,9 +951,9 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modifi
}

static const zend_class_entry *resolve_single_class_type(zend_string *name, const zend_class_entry *self_ce) {
if (zend_string_equals_literal_ci(name, "self")) {
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) {
return self_ce;
} else if (zend_string_equals_literal_ci(name, "parent")) {
} else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
return self_ce->parent;
} else {
return zend_lookup_class_ex(name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ static const char *zend_asymmetric_visibility_string(uint32_t fn_flags) /* {{{ *

static zend_string *resolve_class_name(const zend_class_entry *scope, zend_string *name) {
ZEND_ASSERT(scope);
if (zend_string_equals_literal_ci(name, "parent") && scope->parent) {
if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_PARENT)) && scope->parent) {
if (scope->ce_flags & ZEND_ACC_RESOLVED_PARENT) {
return scope->parent->name;
} else {
return scope->parent_name;
}
} else if (zend_string_equals_literal_ci(name, "self")) {
} else if (zend_string_equals_ci(name, ZSTR_KNOWN(ZEND_STR_SELF))) {
return scope->name;
} else {
return name;
Expand Down Expand Up @@ -390,8 +390,8 @@ static void track_class_dependency(zend_class_entry *ce, zend_string *class_name
ZEND_ASSERT(class_name);
if (!CG(current_linking_class) || ce == CG(current_linking_class)) {
return;
} else if (zend_string_equals_literal_ci(class_name, "self")
|| zend_string_equals_literal_ci(class_name, "parent")) {
} else if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_SELF))
|| zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/opcache/zend_persist.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name)
{
uint32_t ret;

if (zend_string_equals_literal_ci(type_name, "self") ||
zend_string_equals_literal_ci(type_name, "parent")) {
if (zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_SELF)) ||
zend_string_equals_ci(type_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2666,14 +2666,14 @@ ZEND_METHOD(ReflectionParameter, getClass)
zend_string *class_name;

class_name = ZEND_TYPE_NAME(param->arg_info->type);
if (zend_string_equals_literal_ci(class_name, "self")) {
if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_SELF))) {
ce = param->fptr->common.scope;
if (!ce) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Parameter uses \"self\" as type but function is not a class member");
RETURN_THROWS();
}
} else if (zend_string_equals_literal_ci(class_name, "parent")) {
} else if (zend_string_equals_ci(class_name, ZSTR_KNOWN(ZEND_STR_PARENT))) {
ce = param->fptr->common.scope;
if (!ce) {
zend_throw_exception_ex(reflection_exception_ptr, 0,
Expand Down
7 changes: 2 additions & 5 deletions ext/standard/browscap.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,7 @@ static HashTable *browscap_entry_to_array(browser_data *bdata, browscap_entry *e

if (entry->parent) {
ZVAL_STR_COPY(&tmp, entry->parent);
key = ZSTR_INIT_LITERAL("parent", 0);
ZSTR_H(key) = zend_inline_hash_func("parent", sizeof("parent")-1);
zend_hash_add_new(ht, key, &tmp);
zend_string_release_ex(key, false);
zend_hash_add_new(ht, ZSTR_KNOWN(ZEND_STR_PARENT), &tmp);
}

browscap_entry_add_kv_to_existing_array(bdata, entry, ht);
Expand Down Expand Up @@ -333,7 +330,7 @@ static void php_browscap_parser_cb(zval *arg1, zval *arg2, zval *arg3, int callb
new_value = browscap_intern_str(ctx, Z_STR_P(arg2), persistent);
}

if (zend_string_equals_literal_ci(Z_STR_P(arg1), "parent")) {
if (zend_string_equals_ci(Z_STR_P(arg1), ZSTR_KNOWN(ZEND_STR_PARENT))) {
/* parent entry cannot be same as current section -> causes infinite loop! */
if (ctx->current_section_name != NULL &&
zend_string_equals_ci(ctx->current_section_name, Z_STR_P(arg2))
Expand Down
Loading