Skip to content

Commit f5fd079

Browse files
committed
Move the inheritance check of trait methods after the copying of the op_array
1 parent 66a7111 commit f5fd079

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

Zend/zend_inheritance.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,13 @@ static zend_always_inline inheritance_status do_inheritance_check_on_method_ex(
11881188
perform_delayable_implementation_check(ce, child, child_scope, parent, parent_scope);
11891189
}
11901190

1191-
if (!check_only && child->common.scope == ce) {
1191+
if (
1192+
!check_only
1193+
&& (
1194+
child->common.scope == ce
1195+
|| (child->common.fn_flags & ZEND_ACC_TRAIT_CLONE)
1196+
)
1197+
) {
11921198
child->common.fn_flags &= ~ZEND_ACC_OVERRIDE;
11931199
}
11941200

@@ -1946,7 +1952,7 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
19461952
{
19471953
zend_function *existing_fn = NULL;
19481954
zend_function *new_fn;
1949-
bool inherited = false;
1955+
bool check_inheritance = false;
19501956

19511957
if ((existing_fn = zend_hash_find_ptr(&ce->function_table, key)) != NULL) {
19521958
/* if it is the same function with the same visibility and has not been assigned a class scope yet, regardless
@@ -1981,14 +1987,7 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
19811987
ZSTR_VAL(ce->name), ZSTR_VAL(name),
19821988
ZSTR_VAL(existing_fn->common.scope->name), ZSTR_VAL(existing_fn->common.function_name));
19831989
} else {
1984-
/* Inherited members are overridden by members inserted by traits.
1985-
* Check whether the trait method fulfills the inheritance requirements. */
1986-
do_inheritance_check_on_method(
1987-
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
1988-
ce, NULL, /* check_visibility */ 1);
1989-
1990-
inherited = !(existing_fn->common.fn_flags & ZEND_ACC_PRIVATE)
1991-
&& !(existing_fn->common.fn_flags & ZEND_ACC_CTOR && !(existing_fn->common.fn_flags & ZEND_ACC_ABSTRACT));
1990+
check_inheritance = true;
19921991
}
19931992
}
19941993

@@ -2009,8 +2008,12 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
20092008
fn = zend_hash_update_ptr(&ce->function_table, key, new_fn);
20102009
zend_add_magic_method(ce, fn, key);
20112010

2012-
if (inherited && new_fn->common.fn_flags & ZEND_ACC_OVERRIDE) {
2013-
new_fn->common.fn_flags &= ~ZEND_ACC_OVERRIDE;
2011+
if (check_inheritance) {
2012+
/* Inherited members are overridden by members inserted by traits.
2013+
* Check whether the trait method fulfills the inheritance requirements. */
2014+
do_inheritance_check_on_method(
2015+
fn, fixup_trait_scope(fn, ce), existing_fn, fixup_trait_scope(existing_fn, ce),
2016+
ce, NULL, /* check_visibility */ 1);
20142017
}
20152018
}
20162019
/* }}} */

0 commit comments

Comments
 (0)