Re:Upcoming changes in PHP 7.1
by vertex-four on Monday May 23, 2016 @07:25AM
(#11753121)
If you're using type signatures, the alternative is probably going to be that your program crashes at a later time. "Foo is not a Bar" is a better error message than "$foo->xyz() isn't a function", and this happens much closer to the point where you've messed up.
[ Parent
| on HN ]
I disagree. I think that this type of "late type binding" is actually an advantage of dynamically typed languages. That way it does not matter if you pass a map/array/dictionary or an instance of a class as long as the properties are the same.
Re:Upcoming changes in PHP 7.1
by chrisseaton on Monday May 23, 2016 @07:41AM
(#11753190)
I think one problem is when your object quacks like a duck, but the quack doesn't mean what you think it means.
Having methods that just have the right names is a pretty weak assurance, isn't it?
"Fail Fast" is a pretty popular best-practice and failing immediately on a mismatched type hint is in line with that.
The type hinting is optional, so if you want "late type binding" you can just omit the type hints.
Re:Upcoming changes in PHP 7.1
by vertex-four on Monday May 23, 2016 @10:48AM
(#11754175)
Then... don't specify that you want a specific type?