DarkWater Posted October 27, 2008 Share Posted October 27, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/ Share on other sites More sharing options...
corbin Posted October 28, 2008 Share Posted October 28, 2008 Oooo nifty.... I probably won't use that much, but cool. Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/#findComment-676198 Share on other sites More sharing options...
DarkWater Posted October 28, 2008 Author Share Posted October 28, 2008 Oooo nifty.... I probably won't use that much, but cool. There's also closures, which basically "wrap" functions (and variables), and allow calls to the functions to modify variables within the closure. Perl has a similar construct. Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/#findComment-676207 Share on other sites More sharing options...
trq Posted October 28, 2008 Share Posted October 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/#findComment-676219 Share on other sites More sharing options...
DarkWater Posted October 28, 2008 Author Share Posted October 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/#findComment-676223 Share on other sites More sharing options...
Daniel0 Posted October 28, 2008 Share Posted October 28, 2008 I've known for a long time. It's one of the accepted PHP RFCs: http://wiki.php.net/rfc/closures Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/#findComment-676355 Share on other sites More sharing options...
DarkWater Posted October 28, 2008 Author Share Posted October 28, 2008 Yeah, I found out like 2 weeks ago, but I forgot to post. xD Quote Link to comment https://forums.phpfreaks.com/topic/130356-php53-lambdas-and-closures/#findComment-676424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.