static return type in PHP 7 interfaces

2020 update

Static return types have been introduced in PHP 8.


It's not a bug, it just doesn't make sense design-wise from an object-oriented programming perspective.

If your BigInteger and BigDecimal implement both BigNumber, you care about the contract they fulfil. I this case, it's BigNumber's interface.

So the return type you should be using in your interface is BigNumber since anybody coding against that interface does not know anything else than members of that interface. If you need to know about which one is returned, the interface is perhaps too wide in the first place.

Note: programming languages with generics can achieve this effect by specifying the return type as the generic type, but PHP does not have generics and probably will not have in the near future.