Can you override interface methods with different, but “compatible”, signatures?

后端 未结 7 1167
长发绾君心
长发绾君心 2021-02-07 01:32

Consider the following PHP interfaces:

interface Item {
    // some methods here
}

interface SuperItem extends Item {
    // some extra methods here, not define         


        
7条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 01:53

    The problem is not in the IDE. In PHP you cannot override a method. And the compatibility is only in the opposite direction - you can safely expect an instance of the parent class and receive a subclass. But when you expect a subclass, you cannot be safe if you receive the parent class - the subclass may define methods that do not exist in the parent. But still, you can't override the method

提交回复
热议问题