Jul 2 2009

The beauty of PHP is that people can modify it to work however they want due to it’s open sourced nature…

If something annoys you about the programming language itself, you can just go ahead and change it. The upside to that is that you get the features you think are missing in PHP. The downside is that your code can potentially become incompatible with everyone else, and your code becomes quite unportable.

Nonetheless, Ilia Alshanetsky (author of php|architect’s Guide to PHP Security) has posted on his blog a patch of PHP 5.3 that provides proper, traditional, type hinting, currently unsupported for scalar types.

As he explains, type hinting is a controversial topic; what with the fluidity of PHP and it’s loosely-typed nature. However I think type hinting, especially strict type hinting would be more advantageous than disadvantageous. He explains how his patch adds a certain amount of flexibilty for numbers within strings (using the “numeric” pseudo-type) allowing a string to be passed off as a number (perfectly legal in PHP… e.g. “1″ + “1″ = 2), or alternatively using the stricter “int” type to specify a number and must be of integer type i.e. “1″ is not valid, but 1 is.

Unfortunately I don’t like delving into compiling stuff, so I’ll just have to hope it gets included in the main trunk of PHP… until then I can pretend I have type hinting, perhaps by adding comments such as this messy mess… *ahem*:

function foo(/* int */ $bar)

Leave a Reply