Skip to content

Commit cd63806

Browse files
committed
Store prop info name in CG(context) instead of prop info
The prop info is not always available, e.g. when compiling the default value. See phpGH-17378
1 parent 0e1fbf9 commit cd63806

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

Zend/zend_compile.c

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void zend_oparray_context_begin(zend_oparray_context *prev_context, zend_op_arra
342342
CG(context).brk_cont_array = NULL;
343343
CG(context).labels = NULL;
344344
CG(context).in_jmp_frameless_branch = false;
345-
CG(context).active_property_info = NULL;
345+
CG(context).active_property_info_name = NULL;
346346
CG(context).active_property_hook_kind = (zend_property_hook_kind)-1;
347347
}
348348
/* }}} */
@@ -5100,13 +5100,13 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast,
51005100
zend_property_hook_kind hook_kind = zend_get_property_hook_kind_from_name(hook_name);
51015101
ZEND_ASSERT(hook_kind != (uint32_t)-1);
51025102

5103-
const zend_property_info *prop_info = CG(context).active_property_info;
5104-
if (!prop_info) {
5103+
const zend_string *prop_info_name = CG(context).active_property_info_name;
5104+
if (!prop_info_name) {
51055105
zend_error_noreturn(E_COMPILE_ERROR, "Must not use parent::$%s::%s() outside a property hook",
51065106
ZSTR_VAL(property_name), ZSTR_VAL(hook_name));
51075107
}
51085108

5109-
const char *unmangled_prop_name = zend_get_unmangled_property_name(prop_info->name);
5109+
const char *unmangled_prop_name = zend_get_unmangled_property_name(prop_info_name);
51105110
if (!zend_string_equals_cstr(property_name, unmangled_prop_name, strlen(unmangled_prop_name))) {
51115111
zend_error_noreturn(E_COMPILE_ERROR, "Must not use parent::$%s::%s() in a different property ($%s)",
51125112
ZSTR_VAL(property_name), ZSTR_VAL(hook_name), unmangled_prop_name);
@@ -8242,7 +8242,7 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
82428242

82438243
static zend_op_array *zend_compile_func_decl_ex(
82448244
znode *result, zend_ast *ast, enum func_decl_level level,
8245-
const zend_property_info *property_info,
8245+
zend_string *property_info_name,
82468246
zend_property_hook_kind hook_kind
82478247
) {
82488248
zend_ast_decl *decl = (zend_ast_decl *) ast;
@@ -8340,7 +8340,7 @@ static zend_op_array *zend_compile_func_decl_ex(
83408340
}
83418341

83428342
zend_oparray_context_begin(&orig_oparray_context, op_array);
8343-
CG(context).active_property_info = property_info;
8343+
CG(context).active_property_info_name = property_info_name;
83448344
CG(context).active_property_hook_kind = hook_kind;
83458345

83468346
{
@@ -8557,7 +8557,7 @@ static void zend_compile_property_hooks(
85578557
hook->name = zend_strpprintf(0, "$%s::%s", ZSTR_VAL(prop_name), ZSTR_VAL(name));
85588558

85598559
zend_function *func = (zend_function *) zend_compile_func_decl_ex(
8560-
NULL, (zend_ast *) hook, FUNC_DECL_LEVEL_NESTED, prop_info, hook_kind);
8560+
NULL, (zend_ast *) hook, FUNC_DECL_LEVEL_NESTED, prop_info->name, hook_kind);
85618561

85628562
func->common.prop_info = prop_info;
85638563

@@ -8657,12 +8657,8 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
86578657
zend_type type = ZEND_TYPE_INIT_NONE(0);
86588658
flags |= zend_property_is_virtual(ce, name, hooks_ast, flags) ? ZEND_ACC_VIRTUAL : 0;
86598659

8660-
/* FIXME: This is a dirty fix to maintain ABI compatibility. We don't
8661-
* have an actual property info yet, but we really only need the name
8662-
* anyway. We should convert this to a zend_string. */
8663-
ZEND_ASSERT(!CG(context).active_property_info);
8664-
zend_property_info dummy_prop_info = { .name = name };
8665-
CG(context).active_property_info = &dummy_prop_info;
8660+
ZEND_ASSERT(!CG(context).active_property_info_name);
8661+
CG(context).active_property_info_name = name;
86668662

86678663
if (!hooks_ast) {
86688664
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
@@ -8757,7 +8753,7 @@ static void zend_compile_prop_decl(zend_ast *ast, zend_ast *type_ast, uint32_t f
87578753
zend_compile_attributes(&info->attributes, attr_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY, 0);
87588754
}
87598755

8760-
CG(context).active_property_info = NULL;
8756+
CG(context).active_property_info_name = NULL;
87618757
}
87628758
}
87638759
/* }}} */
@@ -9613,9 +9609,9 @@ static bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
96139609
}
96149610
break;
96159611
case T_PROPERTY_C: {
9616-
const zend_property_info *prop_info = CG(context).active_property_info;
9617-
if (prop_info) {
9618-
ZVAL_STR(zv, zend_copy_unmangled_prop_name(prop_info->name));
9612+
zend_string *prop_info_name = CG(context).active_property_info_name;
9613+
if (prop_info_name) {
9614+
ZVAL_STR(zv, zend_copy_unmangled_prop_name(prop_info_name));
96199615
} else {
96209616
ZVAL_EMPTY_STRING(zv);
96219617
}

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ typedef struct _zend_oparray_context {
204204
int last_brk_cont;
205205
zend_brk_cont_element *brk_cont_array;
206206
HashTable *labels;
207-
const zend_property_info *active_property_info;
207+
zend_string *active_property_info_name;
208208
zend_property_hook_kind active_property_hook_kind;
209209
bool in_jmp_frameless_branch;
210210
} zend_oparray_context;

0 commit comments

Comments
 (0)