More type hinting added to PHP trunk
2010-08-08While not really "hinting" so much as checking/enforcing, I find type hinting in PHP 5 to be very handy, so I was happy to see that the next version of PHP (5.4? 6?) includes an expanded list of options. Source: http://schlueters.de/blog/archives/139-Scalar-type-hints-in-PHP-trunk.html. This isn't set in stone yet, but I've wanted this feature for years now so I thought I'd talk about it for a bit.
In vanilla PHP 5.3 you can currently type hint for arrays and objects (and importantly, object interfaces, which allows for duck typing, a hallmark of dynamic languages). This new enhancement allows you to type hint for scalar types like int, float, etc... Previously if you wanted to do that in PHP you had to convert your parameters to Value Objects and then type hint for those objects (typically using the SplTypes classes in the Standard PHP Library).
The comments on the above post definitely show mixed opinions on the topic, but I for one am all for it since it makes defensive coding that much easier to do and helps make method signatures more explicit. Above all else, this is an optional feature that coders are free to ignore, but I like having the option.