“interface is a contract and must be enforced” — indeed, but there are degrees of definition and degrees of enforcement. Type hinting in functions is a quality of the language, not of interfaces in a given language. This my problem with the title — lack of type hinting isn’t a problem of the interfaces in PHP, it was a problem of the language itself. An example of a problem of interfaces is, for example, that in PHP5 you couldn’t implement DateTime interface.

An example to degree of definition is that my contract (the interface) says that a method must be implement. That’s it, that’s the extent of the contract. The fact that in PHP5 I couldn’t have a more detailed contract definition doesn’t mean there’s no contract. It’s great that PHP7 added that feature, but even before it was neither a problem of interface, nor a lack of contracts. It was just a limitation that forced those people that don’t believe in ‘convention over configuration’ to find workarounds.

“to make them more object-oriented” — type hinting has *nothing* to do with OOP. It’s a widely accepted association mostly due to Java and the Java-fication of PHP (a lot of it driven by Symfony).

It’s slightly worrying that mot of the complaints seem to reflect a sort of fundamentalism I’ve often seen in people coming from Java/C (or related) background where the attitude is “if there’s some feature in this languages that isn’t in others, then those other languages aren’t fully OOP.

Finally, you’re dead wrong about covariance/contravariance, but mostly because of the way you explained it. Covariance means I should be able to use instances of type A wherever I’m expecting a compatible class (any sort of parent of A upwards on a lineage compatible with my typehinting). PHP allows you to do that (if A implements XInterface and function doX(XInterface $x) then I can use A in calls to doX for whatever You can’t type hint covariantly, that’s true, but then again there’s nowhere in the world where it says that it’s an OOP feature (and as far as I know it’s not a full feature outside the DotNet family).


Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store