Conflict with PHP attribute when a class implements an interface

I have a class that implements an interface for the execute method.

The interface forces the execute method to have two arguments with some types of hints.

I also use a trait that has an execute method, but with different functionality and signature. I change the name of the attribute method using:

 class MyClass implements MyInterface { use MyTrait { execute as protected commanderExecute; } public function execute(SomeInterface $arg1, SomeInterface2 $arg2) { // do something } } 

When I try to run the application, it throws a Fatal error exception with the following message:

The trait method commanderExecute is not applied because there are collisions with other trait methods on ...

+5
source share
1 answer

Try the following:

 class MyClass implements MyInterface { use MyTrait { MyTrait::execute as protected commanderExecute; } public function execute(SomeInterface $arg1, SomeInterface2 $arg2) { // do something } } 
-1
source

Source: https://habr.com/ru/post/1200600/


All Articles