Compatible Only Interface

../_images/compatible_interface.png

Interfaces are contracts that defines methods signatures, which the derived classes have to implements.

One lesser known fact is that the implementation only has to be compatible with the interface, there is no need to be identical. It is the same behavior than with class inheritance.

This explains that the following code is valid, both with argument contra-variance and return type variance.

Note that the names of the parameters are completely free to be changed at will, yet it is not recommended.

See Also

PHP Features