Re: PATCH: Implementing closures in PHP

php.internals

Ryusuke SEKIYAMA

18 years ago
>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 */

Xuefer Tinys

18 years ago
On Dec 29, 2007 12:45 AM, Ryusuke SEKIYAMA <rsky0711@gmail.com> wrote:
> >any idea about the possibility of hash conflict? > > How about this patch? > http://www.opendogs.org/pub/php-5.3dev-071228a.patch
yeah build_runtime_defined_function_key! that's what i thought of :) and i hope the function name cv works as expected so no hash() on the looong name is needed at run time, and assume that modern cpu will do long memcmp/strcmp quick enough

Marcus Börger

18 years ago
Hello Ryusuke, generally I like both. But could you provide separate patches? marcus Friday, December 28, 2007, 5:45:03 PM, you wrote:
>>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 > */
Best regards, Marcus

Ryusuke SEKIYAMA

18 years ago
Hi, Marcus. 2007/12/31, Marcus Boerger <helly@php.net>:
> Hello Ryusuke, > > generally I like both. But could you provide separate patches?
Yes, I can. Here is the anonymous function patch for PHP 5.3, http://www.opendogs.org/pub/php-5.3dev-080101-anon.patch the square bracket array syntax patch for PHP 5.3, http://www.opendogs.org/pub/php-5.3dev-080101-sbar.patch and the anonymous function patch for PHP 6.0. http://www.opendogs.org/pub/php-6.0dev-080101-anon.patch Regards.
-- /** * Ryusuke SEKIYAMA * rsky0711@gmail.com */

Stanislav Malyshev

18 years ago
> the square bracket array syntax patch for PHP 5.3, > http://www.opendogs.org/pub/php-5.3dev-080101-sbar.patch
I remember we discussed that already and it was rejected then (even though myself and Andi liked it) - did the people that objected then change their minds?
-- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

Marcus Börger

18 years ago
Hello Stanislav, tha makesw three then already, how about we ask around again? Ryusuke, can you please start a new '[RFC] Square brackets shortcut' thread to collect opinions and pass along the patch for that? I like the anonymous function patch too. It is clean and simple. Maybe you want to start a second '[RFC] Anonymous functions' thread with that patch. Can you also please add tests for both? marcus Wednesday, January 2, 2008, 7:51:06 PM, you wrote:
>> the square bracket array syntax patch for PHP 5.3, >> http://www.opendogs.org/pub/php-5.3dev-080101-sbar.patch
> I remember we discussed that already and it was rejected then (even > though myself and Andi liked it) - did the people that objected then > change their minds?
Best regards, Marcus