diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-03-03 14:31:09 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-03-10 16:01:13 +0100 |
commit | fff5771cccaca49565c90349320f3c06cbe19328 (patch) | |
tree | 9e47e32c4f3f1da0211b5243fa9f0a503fd71090 /Zend/zend_inheritance.c | |
parent | d2b902f174b2e8c98bf5d4e257924a96b1323776 (diff) | |
download | php-git-fff5771cccaca49565c90349320f3c06cbe19328.tar.gz |
Require non-absolute trait method refs to be unambiguous
Currently, when writing something like
class X {
use T1, T2 {
func as otherFunc;
}
function func() {}
}
where both T1::func() and T2::func() exist, we will simply assume
that func refers to T1::func(). This is surprising, and it doesn't
really make sense that this particular method gets picked.
This commit validates that non-absolute method references are
unambiguous, i.e. refer to exactly one method. If there is
ambiguity, it is required to write T1::func as otherFunc or
similar.
Closes GH-5232.
Diffstat (limited to 'Zend/zend_inheritance.c')
-rw-r--r-- | Zend/zend_inheritance.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c index a031207b85..eab275e509 100644 --- a/Zend/zend_inheritance.c +++ b/Zend/zend_inheritance.c @@ -1858,8 +1858,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)); } } } |