Rss subscribe!
It's free.

about

A blog about web development and starting up online.


who

Eran Galperin is the techfounder, an Internet entrepreneur and web technologies expert.

28 May

PHP syntax mixings

on 3:40 pm

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.

Share this article: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • DZone
  • del.icio.us
  • Technorati

Posted under PHP, Web development

2 Comments »

  1. 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

  2. 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

RSS feed for comments on this post. TrackBack URL

Leave a comment

Some rights reserved, Eran Galperin
CC 2008 - The Future