Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-在接口类中使用_调用函数_Php_Oop - Fatal编程技术网

PHP-在接口类中使用_调用函数

PHP-在接口类中使用_调用函数,php,oop,Php,Oop,可以将magic function _调用作为抽象并包含在接口类中,以便所有实现类都绑定到包含_调用函数吗? 谢谢在您询问是否可以完成某项工作之前,进行一些测试可能更容易 第5行命令行代码中的(Foo::_调用) $ php -r ' interface Foo{ public function __call($a,$b); } class Bar implements Foo{} ' PHP Fatal error: Class Bar contains 1 abstract metho

可以将magic function _调用作为抽象并包含在接口类中,以便所有实现类都绑定到包含_调用函数吗?
谢谢

在您询问是否可以完成某项工作之前,进行一些测试可能更容易

第5行命令行代码中的(Foo::_调用)

$ 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
第5行命令行代码中的(Foo::_调用)

$ 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

接口是任何实现它的类都必须履行的契约。 若接口将包含_call()方法,那个么它将是一种什么样的契约

接口是类实现某些指定功能的保证__call()不是“指定的功能”。这是相当缺乏的


所以,即使有可能,这绝对是你不应该做的事情。

我已经测试过了。。只是想知道使用像_call这样的神奇函数作为抽象并在接口中使用是否是正确的方法。