Jump to content

PHP5.3 - Lambdas and Closures


DarkWater

Recommended Posts

Well, I recently found out that PHP5.3 is planning to have both lambdas and closures added.  I personally think this is great news, because they make one-time use functions so much easier.

 

$sort = function ($a, $b) {
        return strcmp($a, $b);
};
usort($array, $sort); //btw I know that sort() would do probably do the same thing, this was just an example

 

Opinions?

Link to comment
Share on other sites

Where are we hearing this stuff?

 

I'm using 5.3 for several projects at the moment but haven't come accross anything like this.

 

Someone developed a patch for it, and apparently PHP acknowledged it.  Check out http://us.php.net/call_user_func_array

Example #3:

<?php

$func = function($arg1, $arg2) {
    return $arg1 * $arg2;
};

var_dump(call_user_func($func, 2, 4)); /* As of PHP 5.3.0 */
// int(

?>

 

EDIT: Forgot I had the patch notice bookmarked. http://news.php.net/php.internals/38290

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.