[英]PHP Trait conflict when class implements interface
我有一个实现execute
方法接口的类。
该接口强制execute
方法具有两个带有某些类型提示的参数。
此外,我正在使用具有execute
方法但具有不同功能和签名的特征。 我使用以下方法更改了特征方法名称:
class MyClass implements MyInterface {
use MyTrait
{
execute as protected commanderExecute;
}
public function execute(SomeInterface $arg1, SomeInterface2 $arg2)
{
// do something
}
}
当我尝试运行应用程序时,会抛出致命错误异常,并显示以下消息:
特征方法commanderExecute尚未应用,因为与其他特征方法存在冲突...
尝试这个:
class MyClass implements MyInterface {
use MyTrait
{
MyTrait::execute as protected commanderExecute;
}
public function execute(SomeInterface $arg1, SomeInterface2 $arg2)
{
// do something
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.