Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34633 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37997 invoked by uid 1010); 10 Jan 2008 10:20:53 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 37982 invoked from network); 10 Jan 2008 10:20:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jan 2008 10:20:53 -0000 Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:56370] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/94-03358-481F5874 for ; Thu, 10 Jan 2008 05:20:53 -0500 Received: from dhcp-172-28-204-176.zrh.corp.google.com (unknown [193.142.125.1]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 374A01B365C; Thu, 10 Jan 2008 11:20:50 +0100 (CET) Date: Thu, 10 Jan 2008 11:20:53 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <895124747.20080110112053@marcus-boerger.de> To: "Ryusuke SEKIYAMA" CC: internals@lists.php.net, "Marcus Boerger" In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Anonymous functions From: helly@php.net (Marcus Boerger) Hello Ryusuke, +1, looks pretty nice, makes my life easier in some cases and is closer to other languages like pythin so i can transfer concepts easily which is a big plus for me. marcus Thursday, January 10, 2008, 11:09:26 AM, you wrote: > Hello, lists, > We have discussed about implementing anonymous functions and > closures in PHP. > However, I consider that implementing anonymous functions and > implementing lexical scopes should be discussed separately. > # Even though I like closure. > So I wrote anonymous function patch for PHP 5.3 and 6.0. > Patches (inlcude tests): > for PHP 5.3: http://www.opendogs.org/pub/php-5.3dev-080109-anon.patch > for PHP 6.0: http://www.opendogs.org/pub/php-6.0dev-080109-anon.patch > Featues: > - Unlike create_function(), there is no need to take care of > quotes, backslashes and dollars . > - Can be used in loop, but be compiled only once. > - Supports recursive call using __FUNCTION__. > - Supports inline execution. It works like a block scope. > - Works with opcode caches. > Since I couldn't build APC against PHP 5.3, I have tested > PHP 5.2.5 + anonymous function patch and APC 3.0.16. > Example: > // callback > $arr = array(5, 3, 6, 0); > usort($arr, function($a, $b){ return $a - $b; }); > print_r($arr); // 0, 3, 5, 6 > // assign to a variable > $lambda = function(){ > echo "Hello, World!\n"; > }; > $lambda(); // "Hello, World!" > // inline execution > $result = function($a, $b){ > return $a + $b; > }(1, 2); > var_dump($result); // "int(3)" ?>> > The anonymous function name is composed of '\0', "ZEND_ANON<#serial>", > filename and character position. > - Leading '\0' blocks to be displayed by get_defined_functions(). > - "ZEND_ANON<" helps determine wheter the function is anonymous or not > because '<' cannot be used for user-defined function name. > - Serial number and file informations make the name unique. > - char anon_key_buf[32] is long enough because > `snprintf(anon_key_buf, 32, "ZEND_ANON<%llu>", (unsigned long > long)UINT64_MAX)' > returns 31. > Regards, > 2008/1/6, Marcus Boerger : >> 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 >> >> > -- > /** > * Ryusuke SEKIYAMA > * rsky0711@gmail.com > */ Best regards, Marcus