Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34637 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62947 invoked by uid 1010); 10 Jan 2008 12:10:14 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 62931 invoked from network); 10 Jan 2008 12:10:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jan 2008 12:10:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@googlemail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.146.181 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: rquadling@googlemail.com X-Host-Fingerprint: 209.85.146.181 wa-out-1112.google.com Received: from [209.85.146.181] ([209.85.146.181:16931] helo=wa-out-1112.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/50-59671-32B06874 for ; Thu, 10 Jan 2008 07:10:12 -0500 Received: by wa-out-1112.google.com with SMTP id l24so1249825waf.17 for ; Thu, 10 Jan 2008 04:10:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=yCSxjDqijqixo0FLoZvZrhyHXet/OOmJ/waoZluu4k0=; b=S+SYMddo762VoV4474L5nSP40bmbYPTzUJMaTcM8/JjR0v2pbuFPgOEClYUf4NBQNIakM1T8NOKj7WghYyU7iKFhFAnwXOOcNDx4S+bKK1b03gb2+TgNf3k+9GgFJvMFrDwqDPYdpaV4WGpBFnUX2NZCejK+VHodJ3ucpEqa84E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=cvHsoedClkr26sts8MPPKo2axwxm8pYo77kj+uJE6N48RUZ7QAswdmJ0WazTYJkdxcWGFabHh+3h9dIaajzoSBE0adBFY+6Wkeua3UYlflAmf6SkyCO7Fd//6ImVZH+TH3da7f0p0/KpsSmXHwZohfRXd0FJ/4qEq7QPH68hoC0= Received: by 10.114.210.2 with SMTP id i2mr2202522wag.36.1199967008239; Thu, 10 Jan 2008 04:10:08 -0800 (PST) Received: by 10.114.210.8 with HTTP; Thu, 10 Jan 2008 04:10:08 -0800 (PST) Message-ID: <10845a340801100410s19a14d90u297e44722768c3ec@mail.gmail.com> Date: Thu, 10 Jan 2008 12:10:08 +0000 Reply-To: RQuadling@GoogleMail.com To: "Marcus Boerger" Cc: "Ryusuke SEKIYAMA" , internals@lists.php.net In-Reply-To: <895124747.20080110112053@marcus-boerger.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <895124747.20080110112053@marcus-boerger.de> Subject: Re: [PHP-DEV] [RFC] Anonymous functions From: rquadling@googlemail.com ("Richard Quadling") On 10/01/2008, Marcus Boerger wrote: > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > A nice feature. Especially for array callbacks. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"