Re: PATCH: Implementing closures in PHP
| From: | Ryusuke SEKIYAMA | Date: | Fri, 28 Dec 2007 16:45:03 +0000 |
| Subject: | Re: PATCH: Implementing closures in PHP | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-34272@lists.php.net to get a copy of this message | ||
>any idea about the possibility of hash conflict?
How about this patch?
http://www.opendogs.org/pub/php-5.3dev-071228a.patch
This patch is PHP 5.3 version of the patch I have introduced
in my blog. (written in Japanese)
1. http://d.hatena.ne.jp/rsky/20071126/1196077860
2. http://d.hatena.ne.jp/rsky/20071128/1196260732
3. http://d.hatena.ne.jp/rsky/20071130/1196426672
This patch contains two features, anonymous function and
square bracket array syntax.
Anonymous function can be used in loop (does not exhaust memory
as create_function() in loop), work with opcode caches
and also can be called directly like JavaScript's one.
For example:
% php -r 'print_r(array_map(function($n){ return $n * $n; }, [1, 2, 3]));'
Array
(
[0] => 1
[1] => 4
[2] => 9
)
% php -r 'function($str){ echo $str, "\n"; }("foo");'
foo
More examples are included in this archive:
http://www.opendogs.org/pub/php-5.3dev-071228-anon-patch.zip
--
/**
* Ryusuke SEKIYAMA
* rsky0711@gmail.com
*/