summaryrefslogtreecommitdiff
path: root/Zend/tests/bug62069_2.phpt
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-03-03 14:31:09 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-03-10 16:01:13 +0100
commitfff5771cccaca49565c90349320f3c06cbe19328 (patch)
tree9e47e32c4f3f1da0211b5243fa9f0a503fd71090 /Zend/tests/bug62069_2.phpt
parentd2b902f174b2e8c98bf5d4e257924a96b1323776 (diff)
downloadphp-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/tests/bug62069_2.phpt')
-rw-r--r--Zend/tests/bug62069_2.phpt35
1 files changed, 35 insertions, 0 deletions
diff --git a/Zend/tests/bug62069_2.phpt b/Zend/tests/bug62069_2.phpt
new file mode 100644
index 0000000000..c7c42ba6d1
--- /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--
+<?php
+
+trait T1 {
+ public function func() {
+ echo "From T1\n";
+ }
+}
+
+trait T2 {
+ public function func() {
+ echo "From T2\n";
+ }
+}
+
+class Bar {
+ public function func() {
+ echo "From Bar\n";
+ }
+ use T1 {
+ func as f1;
+ }
+ use T2 {
+ func as f2;
+ }
+}
+
+$b = new Bar();
+$b->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