function test($a = [], $b) {} // Deprecated
function test(Foo $a = null, $b) {} // Allowed
+ . Non-absolute trait method references in trait alias adaptations are now
+ required to be unambiguous:
+
+ class X {
+ use T1, T2 {
+ func as otherFunc;
+ }
+ function func() {}
+ }
+
+ If both T1::func() and T2::func() exist, this code was previously silently
+ accepted, and func as assumed to refer to T1::func. Now it will generate a
+ fatal error instead, and either T1::func or T2::func needs to be written
+ explicitly.
- COM:
. Removed the ability to import case-insensitive constants from type
--- /dev/null
+--TEST--
+Bug #62069: binding wrong traits if they have same name methods
+--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, T2 {
+ func as f1;
+ }
+}
+
+$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
--- /dev/null
+--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
class MyClass {
- use Hello, World { sayHello as sayWorld; }
+ use Hello, World { World::sayHello as sayWorld; }
}
$o = new MyClass();
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));
}
}
}