Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35006 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39923 invoked by uid 1010); 29 Jan 2008 18:26:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 39905 invoked from network); 29 Jan 2008 18:26:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jan 2008 18:26:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=koyhoge@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=koyhoge@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 66.249.82.232 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: koyhoge@gmail.com X-Host-Fingerprint: 66.249.82.232 wx-out-0506.google.com Received: from [66.249.82.232] ([66.249.82.232:63762] helo=wx-out-0506.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/AB-55338-1DF6F974 for ; Tue, 29 Jan 2008 13:26:25 -0500 Received: by wx-out-0506.google.com with SMTP id s14so2192382wxc.26 for ; Tue, 29 Jan 2008 10:26:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=aPlshXsiId+zaRyd1/Cr10QbCLJByf/sLBF6YNN4msk=; b=ABc8EoolJQRxhVdwF7DAWyMZHy2gJ9eEQtNTyYDAF/LapbG85MLSt4JBke8GM+GLtf4I8vkVkuhegQOMaso9lykfZy7uTdung3PB55CGwgHQMPrFOixIJJ6qtXBYGaFroaHJO8a+ogXoldKOkkVdNRAxyoOboggiKTbGfbHDw40= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=rsYocJAUWSzfyG2duGDMyh6uBYmG+Xmbzu/zjiJWIWJeBfIDo4VdhydO2Vmvz5l/HISLP0n+fJ2fUH0gGSd1PEfwV6Zrr70cnvw4NTEA9h7diQV3n64WLbkniDQ/tGzjinxeMH4pV6G1JHzBRbpnUycKoXXfEKtNnt2mdOiXr80= Received: by 10.142.215.5 with SMTP id n5mr3529134wfg.11.1201631181219; Tue, 29 Jan 2008 10:26:21 -0800 (PST) Received: by 10.142.178.8 with HTTP; Tue, 29 Jan 2008 10:26:21 -0800 (PST) Message-ID: Date: Wed, 30 Jan 2008 03:26:21 +0900 Sender: koyhoge@gmail.com To: internals@lists.php.net In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Google-Sender-Auth: d5b6f04e258987c6 Subject: Re: [PHP-DEV] [RFC] Anonymous functions From: koyama@hoge.org ("KOYAMA Tetsuji") Hi lists, Is this discussion stopping? I want this feature in PHP. Please start to talk. On Jan 10, 2008 7:09 PM, Ryusuke SEKIYAMA 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 > */ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > - KOYAMA, Tetsuji koyama@hoge.org