M
M
matperez2015-06-23 11:55:00
Yii
matperez, 2015-06-23 11:55:00

Is there any way to force PHP to take into account that the method described in the interface is implemented in the magic method?

Hello!
I wrote a certain class and decided to describe the requirements for it in the form of an interface. I implemented some of the required methods directly, and some have already been implemented through the Yii behavior. In the IDE, I can take this into account through PHPDOC @method, but PHP itself puts a bolt on this and states that for full-fledged work, the missing methods still need to be implemented. I end up with an error: Class contains N abstract methods and must therefore be declared abstract or implement the remaining methods
Is there any way to make PHP believe that a method declared in an interface is implemented through magic?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
matperez, 2015-06-23
@matperez

In general, as Sergei Protko said , interface methods must be implemented explicitly. I met a variant on the Internet where for each "magic" method they make a stub through return $this->__call(__FUNCTION__, func_get_args()), but this is somehow not a fountain, as well as the need to invent a new name for the method. I solved it through Trait with all the missing methods, and inside the trait I call the original methods through parent::methodName().

A
Andrey Mokhov, 2015-06-23
@mokhovcom

if you implement an interface then you must implement all the methods declared in it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question