There has been some discussion on the PHP internals list on adding a short syntax array seen in other languages. The short syntax array defines an array directly with the array operator brackets:
$array = array(1,4,array(5,9),array(3,'name')); // Old way $array = [1,4,[5,9],[3,'name']]; // Shorter syntax
The shorter syntax is both more readable and more welcoming to programmers coming from other languages. I read about this on Brian Moon’s blog, and among one of the comments I read an interesting thought:
Yes, would be a nice addition. Though I’d rather the anonymous object syntax came too, would be much more useful, with callbacks etc.
visit({ function accept() { … } });
I think the commentator was actually referring to anonymous functions (which are objects in Javascript). If PHP implemented anonymous functions (and maybe closures?) it would become very powerful (callbacks anyone?), sort of like Javascript with real class based OO. Food for thought.




2008 - The Future
I did mean anonymous objects.
Anonymous function would be visit(function() { .. }); which is useful, but often alittle more that just a single function.
There was a discussion on internals about anonymous functions & closures awhile back, I believe even patches appeared for the former, but not to sure on the latter, as obviously would be bit more involved.
Comment by Jared — 28 May @ 5:36 pm
Interesting.
I think anonymous functions are more useful, since you could still pass an object instance at run time, but you can’t pass a function as an argument (much less declare it anonymously).
Comment by Eran Galperin — 28 May @ 6:05 pm