如何使用同名方法处理特征?
trait FooTrait {
public function fooMethod() {
return 'foo method';
}
public function getRow() {
return 'foo row';
}
}
trait TooTrait {
public function tooMethod() {
return 'too method';
}
public function getRow() {
return 'too row';
}
}
class Boo
{
use FooTrait;
use TooTrait;
public function booMethod() {
return $this->fooMethod();
}
}
错误,
致命错误:尚未应用特征方法 getRow,因为与 Boo 中的其他特征方法发生冲突...
我该怎么办?
而且,有两个相同的方法名称,我怎样才能得到方法trait FooTrait
?
$a = new Boo;
var_dump($a->getRow()); // Fatal error: Call to undefined method Boo::getRow() in...
编辑:
class Boo
{
use FooTrait, TooTrait {
FooTrait::getRow insteadof TooTrait;
}
public function booMethod() {
return $this->fooMethod();
}
}
如果我也想getRow
从TooTrait
via获取方法Boo
怎么办?可能吗?