将魔术函数__call作为一个抽象并包含在接口类中是否可以将所有实现类绑定到包含__call函数? 感谢
答案 0 :(得分:1)
在你询问是否可以做某事之前,也许更容易做一些测试。
第5行的命令行代码中的$ 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)
第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)
答案 1 :(得分:0)
接口是实现它的任何类必须满足的合同。 如果接口包含__call()方法,那将是什么样的合同?
接口保证了类将实现某些指定的功能。 __call()不是指定的功能'。它缺乏它。
所以,即使有可能,这肯定是你不应该做的事情。