@@ -1139,7 +1139,7 @@ static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zen
11391139}
11401140/* }}} */
11411141
1142- static void zend_add_trait_method (zend_class_entry * ce , const char * name , zend_string * key , zend_function * fn , HashTable * * overriden ) /* {{{ */
1142+ static void zend_add_trait_method (zend_class_entry * ce , const char * name , zend_string * key , zend_function * fn , uint32_t is_aliased , HashTable * * overriden ) /* {{{ */
11431143{
11441144 zend_function * existing_fn = NULL ;
11451145 zend_function * new_fn ;
@@ -1191,7 +1191,10 @@ static void zend_add_trait_method(zend_class_entry *ce, const char *name, zend_s
11911191 }
11921192 return ;
11931193 } else if (UNEXPECTED (existing_fn -> common .scope -> ce_flags & ZEND_ACC_TRAIT )) {
1194- /* two traits can't define the same non-abstract method */
1194+ /* two traits can't define the same non-abstract method unless they are aliased */
1195+ if (is_aliased ) {
1196+ return ;
1197+ }
11951198#if 1
11961199 zend_error_noreturn (E_COMPILE_ERROR , "Trait method %s has not been applied, because there are collisions with other trait methods on %s" ,
11971200 name , ZSTR_VAL (ce -> name ));
@@ -1239,6 +1242,7 @@ static int zend_traits_copy_functions(zend_string *fnname, zend_function *fn, ze
12391242 zend_trait_alias * alias , * * alias_ptr ;
12401243 zend_string * lcname ;
12411244 zend_function fn_copy ;
1245+ uint32_t is_aliased = 0 ;
12421246
12431247 /* aliases which are qualified with a class name won't have any ambiguity. method names try to match with alias->trait_names */
12441248 if (ce -> trait_aliases ) {
@@ -1275,8 +1279,9 @@ static int zend_traits_copy_functions(zend_string *fnname, zend_function *fn, ze
12751279 }
12761280
12771281 lcname = zend_string_tolower (alias -> alias );
1278- zend_add_trait_method (ce , ZSTR_VAL (alias -> alias ), lcname , & fn_copy , overriden );
1282+ zend_add_trait_method (ce , ZSTR_VAL (alias -> alias ), lcname , & fn_copy , 0 , overriden );
12791283 zend_string_release (lcname );
1284+ is_aliased = 1 ;
12801285
12811286 /* Record the trait from which this alias was resolved. */
12821287 if (!alias -> trait_method -> ce ) {
@@ -1334,7 +1339,7 @@ static int zend_traits_copy_functions(zend_string *fnname, zend_function *fn, ze
13341339 }
13351340 }
13361341
1337- zend_add_trait_method (ce , ZSTR_VAL (fn -> common .function_name ), fnname , & fn_copy , overriden );
1342+ zend_add_trait_method (ce , ZSTR_VAL (fn -> common .function_name ), fnname , & fn_copy , is_aliased , overriden );
13381343 }
13391344
13401345 return ZEND_HASH_APPLY_KEEP ;
0 commit comments