Some time ago I wrote an article about the implementation of type hints for non-object types for PHP. Meanwhile many things happened and that implementation was replaced by a different one. Readers of my previous post might know that I have doubts about type hints in PHP. People who met me in person and asked me about it know for sure :-)
So what's the status now? - Well type hints, for non-object types, exist and they don't. There is a valid syntax which looks like this:
function foo(int $i) { echo $i; }
What's the consequence of this code? - Well the type hint is simply ignored. This means that
foo("Hello world");
Will run without any error and print Hello world. So there is an syntax looking like another part of the language which throws errors but behaves completely different.
function foo(bar $b) { } foo("bar");' Catchable fatal error: Argument 1 passed to foo() must be an instance of bar, string given [...]
The int hint is just one of them, there are a few more: