2

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 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have already tested.. just curious whether it is the right approach or not to use magic functions like __call as abstract and use in interface.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.