Quantcast

Anonymous functions in PHP

I ran into this and found it interesting. Someone has added support for anonymous functions in PHP.

With the patch you can now do stuff like:

$data = array("zoo", "orange", "car", "lemon", "apple");
usort($data, function($a, $b) { return strcmp($a, $b); });
var_dump($data); # data is sorted alphabetically

Before you had to use a funky function generation call.

Tags:

This entry was posted in programming and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. SantosJ
    Posted May 18, 2007 at 10:59 am | Permalink

    I stopped following the discussion after a while (and any discussion on the Internals Mailing List). I'm more interested in if they are going to have it in the next version of PHP. The patch is easy enough that you can add it yourself.

    It is good that people with more karma was able to come in and support the idea.

  2. Posted May 18, 2007 at 4:48 pm | Permalink

    Ah, that sounds absolutely delightful! I've always found JavaScript's first-class treatment of anonymous functions quite helpful, it's nice to see it come into PHP now.

  3. Posted May 19, 2007 at 6:21 am | Permalink

    Edward: it's not first-class function. thing which gets into php is much simplier…

    though, it's still not applied to the tree, as far as I know

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>