这不起作用:
interface TestInterface
{
    public function testMethod();
}
interface TestInterface2
{
    public function testMethod();
}
class TestClass implements TestInterface, TestInterface2
{
}
给我错误:
致命错误:无法继承抽象函数TestInterface2 :: testMethod()(之前在TestInterface中声明为abstract).
那是对的吗?为什么不允许这样做?对我没有意义.
抽象函数也会发生这种情况,例如,如果您实现了一个接口,然后从具有相同名称的抽象函数的类继承.
The*_*igB 11
看来当前的PHP版本实际上可以做到这一点.我已跟踪此行为的行为变化:
https://github.com/php/php-src/commit/31ef559712dae57046b6377f07634ad57f9d88cf#Zend/zend_compile.c
因此,从php-5.3.9开始,记录的行为似乎已经发生了变化.
实现包含具有相同签名的方法的两个接口是没有意义的.
编译器无法知道这些方法是否实际具有相同的目的 - 如果不是,则意味着您的类至少不能实现其中一个接口.
例:
interface IProgram { function execute($what); /* executes the given program */ }
interface ISQLQuery { function execute($what); /* executes the given sql query */ }
class PureAwesomeness implements IProgram, ISQLQuery {
    public function execute($what) { /* execute something.. but what?! */ }
}
如您所见,不可能为两个接口实现该方法 - 并且也无法调用实际从给定接口实现该方法的方法.
| 归档时间: | 
 | 
| 查看次数: | 9305 次 | 
| 最近记录: |