Re: [RFC] Anonymous functions
| From: | Marcus Boerger | Date: | Sun, 23 Mar 2008 14:46:34 +0000 |
| Subject: | Re: [RFC] Anonymous functions | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-36385@lists.php.net to get a copy of this message | ||
Hello Ryusuke,
I have put your proposal as a link to a PHP GSoC 2008 idea here:
http://wiki.php.net/gsoc/2008
Feel invited to add to this idea in whatever way you want :-)
marcus
Saturday, February 23, 2008, 7:46:34 PM, you wrote:
> 2008/2/24, Andrei Zmievski <andrei@gravitonic.com>:
>> Do we have a working patch somewhere then?
> Hi, I have added support for closures to my patches.
> http://www.opendogs.org/pub/php-5.3-080223-anon.patch
> http://www.opendogs.org/pub/php-6.0-080223-anon.patch
> http://www.opendogs.org/pub/php-anon-tests-080223.tgz
> Example:
> <?php
> function get_counter($i = 0)
> {
> /**
> * 'static' modified anonymous function's
> * uninitialized (or null) static variables
> * are copied from the declared scope.
> */
> return static function(){
> static $i;
> return ++$i;
> };
> }
> $c1 = get_counter();
> $c2 = get_counter(100);
> var_dump($c1(), $c2());
> var_dump($c1(), $c2());
> var_dump($c1(), $c2());
?>>
> For recursive calling of anonymous functions and closures,
> added function get_current_function_key().
> <?php
> $f = function($i = 0)
> {
> echo "$i ";
> if (++$i > 10) {
> return;
> }
> $f = get_current_function_key();
> $f($i);
> };
> $f();
?>>
> And here is a Zend extension for PHP 5.2 which enables
> anonymous functions, closures and square bracket arrays.
> http://www.opendogs.org/pub/php_qiq-0.1.0pre.tgz
> This has a few more features, but, at present, there is
> no document...
> Regards,
Best regards,
Marcus