Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35559 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18352 invoked by uid 1010); 18 Feb 2008 16:26:51 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 18337 invoked from network); 18 Feb 2008 16:26:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2008 16:26:51 -0000 Authentication-Results: pb1.pair.com header.from=marye@geminisbs.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=marye@geminisbs.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain geminisbs.com from 72.52.154.20 cause and error) X-PHP-List-Original-Sender: marye@geminisbs.com X-Host-Fingerprint: 72.52.154.20 cepheus.geminisbs.net Linux 2.5 (sometimes 2.4) (4) Received: from [72.52.154.20] ([72.52.154.20:58588] helo=cepheus.geminisbs.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/02-32389-AC1B9B74 for ; Mon, 18 Feb 2008 11:26:50 -0500 Received: from localhost (localhost [127.0.0.1]) by cepheus.geminisbs.net (Postfix) with ESMTP id D042498A3E; Mon, 18 Feb 2008 11:26:47 -0500 (EST) X-Virus-Scanned: amavisd-new at X-Spam-Score: -0.519 X-Spam-Level: X-Spam-Status: No, score=-0.519 tagged_above=-10 required=6.6 tests=[AWL=0.034, BAYES_00=-2.599, RCVD_IN_SORBS_DUL=2.046] Received: from cepheus.geminisbs.net ([127.0.0.1]) by localhost (cepheus.geminisbs.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SGximezS-nUU; Mon, 18 Feb 2008 11:26:45 -0500 (EST) Received: from [192.168.0.7] (pool-71-247-245-86.nycmny.east.verizon.net [71.247.245.86]) by cepheus.geminisbs.net (Postfix) with ESMTP id EC37998A2E; Mon, 18 Feb 2008 11:26:43 -0500 (EST) Message-ID: <47B9B1B9.7060601@geminisbs.com> Date: Mon, 18 Feb 2008 11:26:33 -0500 User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: KOYAMA Tetsuji CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Anonymous functions From: marye@geminisbs.com (Matvey Arye) Hi All, I second this. Can we please re-open the discussion on anonymous functions as well as closures. That would be an awesome feature. create_function is a bit ugly semantically to be sufficient for all anonymous function needs. Thanks, Mat KOYAMA Tetsuji wrote: > 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 > >