by TazeTSchnitzel · 12y ago · 0 comments
Hack extends PHP's type hints, it doesn't add them. It also makes PHP statically typed.
PHP does not have type hint for their internal datatypes (int, float, string). Only array is supported. Type hinting for your custom datatypes is supported, when used as function arguments.
Also hack introduces type hint for function return type.
I disagree. PHP finds this perfectly acceptable:
class Foo {}
class Bar {}
function foo(Foo $x) {}
function bar(Bar $x) { foo($x); }
PHP is clearly checking types (actually, class tags) at runtime, every time a function/method is called. That's dynamic typing, not static typing.Crucially, static types can be erased before execution without affecting the behaviour of a program: http://en.wikipedia.org/wiki/Type_erasure
How can a language be statically typed when the instructions telling it what code to use are dynamic?
Also, I don't see how pausing execution and re-invoking the compiler at run-time to load the rest of the code base (which you can do in PHP with a conditional include, don't know about Hack) can't be done with static typing.
It makes it gradually typed. The types are only as static as you choose to make them.