Is it okay to make magic function __call as an abstract and include in interface class so that all the implementation classes are bound to include __call function? Thanks
2 Answers
Maybe it is easier to do some testing before you ask whether something can be done.
$ php -r ' abstract class Foo{ public abstract function __call($a,$b); } class Bar extends Foo{} ' PHP Fatal error: Class Bar contains 1 abstract method and must therefore be declared abstract or implement the remaining methods(Foo::__call) in Command line code on line 5
$ php -r ' interface Foo{ public function __call($a,$b); } class Bar implements Foo{} ' PHP Fatal error: Class Bar contains 1 abstract method and must therefore be declared abstract or implement the remaining methods(Foo::__call) in Command line code on line 5
1 Comment
Interface is the contract that any class that implements it have to fulfill. What kind of the contract it would be if the interface will contain __call() method?
Interface is a guarantee that some specified functionality will be implemented by the class. __call() is not a 'specified functionality'. It is rather lack of it.
So, even if it would be possible this is definitely something that you shouldn't do.