mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Use new known "self" and "parent" zend_strings (#17766)
This commit is contained in:
parent
48866b760f
commit
65d433161a
10 changed files with 24 additions and 27 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -2257,10 +2257,10 @@ simple_list:
|
|||
/* 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()
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue