@@ -1188,7 +1188,13 @@ static zend_always_inline inheritance_status do_inheritance_check_on_method_ex(
1188
1188
perform_delayable_implementation_check (ce , child , child_scope , parent , parent_scope );
1189
1189
}
1190
1190
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
+ ) {
1192
1198
child -> common .fn_flags &= ~ZEND_ACC_OVERRIDE ;
1193
1199
}
1194
1200
@@ -1946,7 +1952,7 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
1946
1952
{
1947
1953
zend_function * existing_fn = NULL ;
1948
1954
zend_function * new_fn ;
1949
- bool inherited = false;
1955
+ bool check_inheritance = false;
1950
1956
1951
1957
if ((existing_fn = zend_hash_find_ptr (& ce -> function_table , key )) != NULL ) {
1952
1958
/* 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_
1981
1987
ZSTR_VAL (ce -> name ), ZSTR_VAL (name ),
1982
1988
ZSTR_VAL (existing_fn -> common .scope -> name ), ZSTR_VAL (existing_fn -> common .function_name ));
1983
1989
} 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;
1992
1991
}
1993
1992
}
1994
1993
@@ -2009,8 +2008,12 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
2009
2008
fn = zend_hash_update_ptr (& ce -> function_table , key , new_fn );
2010
2009
zend_add_magic_method (ce , fn , key );
2011
2010
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 );
2014
2017
}
2015
2018
}
2016
2019
/* }}} */
0 commit comments