Types serve three different functions:
- design
- documentation
- actual type checking
The first two do not require any type checking at all. Thus, even if PHP has not tested the interfaces, they will still be useful for only two reasons.
For example, I always think about my interfaces when I do Ruby, even though Ruby has no interfaces. And I often want to have a way to write these design decisions in source code.
On the other hand, I saw a lot of Java code that used interfaces, but obviously the author never thought about them. In fact, in one case, one could see from the indentation, spaces, and some remaining comments in the interface, which the author actually just copied and pasted the class definition and deleted all the method bodies.
Now to the third question: PHP actually does interface type checking. Just because it checks them at runtime does not mean that it does not print them at all.
And, in fact, it does not even check them at runtime; it checks them at boot time, which happens before execution. And doesn't "type checking happen at runtime, but before that" pretty much the very definition of static type checking?
Jörg W Mittag
source share