mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
fff5771ccc
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.
33 lines
553 B
PHP
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
|