Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35759 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56804 invoked by uid 1010); 23 Feb 2008 19:36:18 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 56789 invoked from network); 23 Feb 2008 19:36:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2008 19:36:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=andi@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=andi@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.162 as permitted sender) X-PHP-List-Original-Sender: andi@zend.com X-Host-Fingerprint: 212.25.124.162 mail.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.162] ([212.25.124.162:5772] helo=mx1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0D/40-30812-0B570C74 for ; Sat, 23 Feb 2008 14:36:18 -0500 Received: from us-ex1.zend.com ([192.168.16.5]) by mx1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 23 Feb 2008 21:36:23 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Sat, 23 Feb 2008 11:36:18 -0800 Message-ID: <698DE66518E7CA45812BD18E807866CE014A9365@us-ex1.zend.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] [RFC] Anonymous functions Thread-Index: Ach1+tX8nvEdJxP/TJ+bngjF3Xyj7AAWCV0g References: <47B9B1B9.7060601@geminisbs.com> <93D0D6BA-34AD-4A17-B474-91B251628EA5@gravitonic.com> To: "Andrei Zmievski" , "Matvey Arye" Cc: "KOYAMA Tetsuji" , X-OriginalArrivalTime: 23 Feb 2008 19:36:23.0187 (UTC) FILETIME=[5F371E30:01C87653] Subject: RE: [PHP-DEV] [RFC] Anonymous functions From: andi@zend.com ("Andi Gutmans") I think we have to be very clear whether we are going to provide just a sexier notation for anonymous functions or closures (and if the latter what the semantics are). Just doing one and not figuring out the long term piece doesn't make sense because we may end up having two completely distinct features and/or feature creep over the next year which doesn't make much sense to me. I think in last discussion most ppl just preferred a sexier anonymous function esp. as there weren't very clear/clean proposals for how closures would work in PHP and what the benefits would be. So I definitely suggest to have a discussion, maybe RFC based like Stefan did but really decide once and for all on where we'd like to go with this. We all know that no features map 1:1 to PHP and there are always unique behaviors of our language and environment which require a fresh view at things. Andi > -----Original Message----- > From: Andrei Zmievski [mailto:andrei@gravitonic.com] > Sent: Friday, February 22, 2008 10:00 AM > To: Matvey Arye > Cc: KOYAMA Tetsuji; internals@lists.php.net > Subject: Re: [PHP-DEV] [RFC] Anonymous functions >=20 > Yes, let's re-open, I'd like to get a closure on that issue (pun > intended). >=20 > -Andrei >=20 > On Feb 18, 2008, at 8:26 AM, Matvey Arye wrote: >=20 > > 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 =3D 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 =3D function(){ > >>> echo "Hello, World!\n"; > >>> }; > >>> $lambda(); // "Hello, World!" > >>> > >>> // inline execution > >>> $result =3D 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 > >> > >> > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php