|
|
|
|
|
by wvenable
4520 days ago
|
|
I disagree. Strict type hinting would be ridiculous in PHP and lead to a lot of unnecessary and unsafe casting. nikic goes through all the scalar type hint options here: http://nikic.github.io/2012/03/06/Scalar-type-hinting-is-har... Strict weak type hinting seems like the most realistic and pragmatic choice except I would add a cast to make sure the type is actually an `int` in the function. |
|
While the idea of "strong weak type hinting" is interesting, and would certainly be useful for some code (especially libraries), it's not what I want from type hinting. At least 70% of the bugs I encounter in the wild are due to unexpected types. SWTH doesn't fix that - if I pass in a string and it looks like a number, the function will blindly accept it. That's not a behavior I want, that's something I want caught before I even think about deploying.
I guess it depends on what you expect type hinting to provide you, but it looks like I'm not alone in wanting guaranteed safety (Facebook and Box seem to agree). Only strict typehinting fixes that.
But, if the community decides that SWTH is worth pursuing I'd like to choose a syntax structure that allows both to coexist. "foo(int $int)" can be strongly-typed, while "foo(~int $int)" can be strongly weakly typed.
[1]: http://www.php.net/manual/en/security.magicquotes.php
Edit: forgot link