Type hint for descendant classes

前端 未结 2 1910
梦如初夏
梦如初夏 2021-01-23 18:45

From the docs page http://php.net/manual/en/language.oop5.typehinting.php

If class or interface is specified as type hint then all its children or implementations are al

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-23 18:50

    From the same typehinting section you linked to:

    The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error.

    For the method signatures to be the same, they must contain the exact same typehints. And also relevant because it is similar...

    From the OOP Basics - extends section of the manual:

    When overriding methods, the parameter signature should remain the same or PHP will generate an E_STRICT level error. This does not apply to the constructor, which allows overriding with different parameters.

提交回复
热议问题