diff --git a/Zend/tests/bug62069.phpt b/Zend/tests/bug62069.phpt new file mode 100644 index 0000000000000..d434e271c6207 --- /dev/null +++ b/Zend/tests/bug62069.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #62069: binding wrong traits if they have same name methods +--FILE-- +f2(); + +?> +--EXPECTF-- +Fatal error: An alias was defined for method func(), which exists in both T1 and T2. Use T1::func or T2::func to resolve the ambiguity in %s on line %d diff --git a/Zend/tests/bug62069_2.phpt b/Zend/tests/bug62069_2.phpt new file mode 100644 index 0000000000000..c7c42ba6d1973 --- /dev/null +++ b/Zend/tests/bug62069_2.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #62069: binding wrong traits if they have same name methods (variation 2) +--FILE-- +f2(); + +?> +--EXPECTF-- +Fatal error: An alias was defined for method func(), which exists in both T1 and T2. Use T1::func or T2::func to resolve the ambiguity in %s on line %d diff --git a/Zend/tests/traits/language011.phpt b/Zend/tests/traits/language011.phpt index 44de874705dd5..1f5b496308878 100644 --- a/Zend/tests/traits/language011.phpt +++ b/Zend/tests/traits/language011.phpt @@ -18,7 +18,7 @@ trait World { class MyClass { - use Hello, World { sayHello as sayWorld; } + use Hello, World { World::sayHello as sayWorld; } } $o = new MyClass(); diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index df84efc389cc8..372430009916e 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1870,8 +1870,12 @@ static void zend_traits_init_trait_structures(zend_class_entry *ce, zend_class_e continue; } - // TODO: This is ambiguous! The first trait is assumed. - break; + zend_error_noreturn(E_COMPILE_ERROR, + "An alias was defined for method %s(), which exists in both %s and %s. Use %s::%s or %s::%s to resolve the ambiguity", + ZSTR_VAL(cur_method_ref->method_name), + ZSTR_VAL(trait->name), ZSTR_VAL(traits[j]->name), + ZSTR_VAL(trait->name), ZSTR_VAL(cur_method_ref->method_name), + ZSTR_VAL(traits[j]->name), ZSTR_VAL(cur_method_ref->method_name)); } } }