php-src/Zend/tests/bug62069.phpt
Nikita Popov fff5771ccc 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.
2020-03-10 16:01:13 +01:00

33 lines
553 B
PHP

--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