Saturday, July 4. 2009

There has been a lot of comments both on this blog and the internals list. There seems to be a fairly large group of core developers who like the idea as well as surpassingly large support base on the user level too (wow, didn't think that this many people want type hinting). Unfortunately, there have also been, as is typically on the internals list a few people complaining for the sake of complaining. Their arguments have ranged from type hinting is against PHP's loosely typed nature and people will mis-use it and make PHP into something that it is not, to I don't need or will use it, so no one should get it.

That said these people are in the minority, albeit a rather vocal one, so progress is being made. There have also been a number of really good suggestions by folks who have reviewed the patch (big thanks guys) and their improvements have been incorporated into the version 2 of the patch. Here is the quick changelog.

1) Added support for "object" type hint
2) Modified the patch not to break binary compatibility so you can now use patched PHP without having to re-compile your extensions or having issues with binary ones.
3) Added full reflection support, which I appropriated from Felipe's earlier work on type hinting
4) Added support for type casting, where by you can do things like this function a((int)$foo), which will force PHP to cast the value of $foo to an integer
5) Added tests, which again I partially appropriated from Felipe's earlier work.

I am posting it here for peer review and comment. If all goes well, I am going to post it to internals for a vote, which will hopefully pass. So, if you want the feature in, or you think its crap, watch internals on Monday so you can make your opinion known via a +/- vote.

array - index can be both integers and strings, elements mixed
array[] - index can be both integers and strings, elements mixed
array[int]string - array of strings with int index
array[int][int]float - matrix of floating-point numbers
array[string]mixed - associative array of generic values
array[]SomeClass - array of objects of the class SomeClass,
the keys can be both integer numbers and strings

Felipe's patch and mine were fairly similar at the onset. The difference is that my patch also support type forcing via (int) and similar. Also, the patch Felipe proposed breaks binary compatibility, while mine retains it, which is important if you intend to apply it against PHP where binary modules are used, especially those you cannot recompile.

Anyway, sounds like yours is the way to go ... I am just curious how that's going to come out, and if I should use it my projects.
I sure would love to have it, at least in my development system, und remove it for production to at least spare the customers the need for rebuilding after each PHP update.

You should never ignore the minority. Just because they're a small group doesn't mean that they won't become majority in the future. And then everyone who ignored them before feels like they missed a huge opportunity.