覆盖使用类型提示的接口父方法

时间:2013-10-18 11:36:33

标签: php interface type-hinting

假设我的老板有一个班级和界面:

class HisBar {}

interface HisFooInterface
{
    public function doSomethingWithBar(HisBar $bar);
}

我有自己的课程,可能会延伸HisBar

class MyBar extends HisBar {}

我希望我能做到这一点:

interface MyFooInterface extends HisFooInterface
{
    public function doSomethingWithBar(MyBar $bar);
}

但是,是的,我收到了错误:

  

致命错误:MyFooInterface :: doSomethingWithBar()声明必须   与HisFooInterface :: doSomethingWithBar(HisBar $ bar)兼容   第xx行上的路径\到\ MyFooInterface.php

我的意思是,我需要使用接口的实例,但具有不同的类型提示,是否可能?有没有办法做到这一点?如何更改参数的类型?感谢。

0 个答案:

没有答案
相关问题