我有一个实现execute
方法接口(interface)的类。
接口(interface)强制 execute
方法有两个带有一些类型提示的参数。
我还使用了一个具有 execute
方法的特征,但具有不同的功能和签名。我通过使用更改特征方法名称:
class MyClass implements MyInterface {
use MyTrait
{
execute as protected commanderExecute;
}
public function execute(SomeInterface $arg1, SomeInterface2 $arg2)
{
// do something
}
}
当我尝试运行该应用程序时,它会抛出一个 fatal error 异常并显示以下消息:
Trait method commanderExecute has not been applied, because there are collisions with other trait methods on ...
最佳答案
试试这个:
class MyClass implements MyInterface {
use MyTrait
{
MyTrait::execute as protected commanderExecute;
}
public function execute(SomeInterface $arg1, SomeInterface2 $arg2)
{
// do something
}
}
关于类实现接口(interface)时PHP Trait冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25365283/