Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38488 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99251 invoked from network); 20 Jun 2008 19:19:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2008 19:19:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.62.56 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.62.56 qmta06.westchester.pa.mail.comcast.net Received: from [76.96.62.56] ([76.96.62.56:54207] helo=QMTA06.westchester.pa.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/51-12821-0C20C584 for ; Fri, 20 Jun 2008 15:19:28 -0400 Received: from OMTA12.westchester.pa.mail.comcast.net ([76.96.62.44]) by QMTA06.westchester.pa.mail.comcast.net with comcast id gBtV1Z0030xGWP8560aV00; Fri, 20 Jun 2008 19:19:26 +0000 Received: from earth.ufp ([24.13.255.226]) by OMTA12.westchester.pa.mail.comcast.net with comcast id gKKR1Z00E4trKQ83YKKRcs; Fri, 20 Jun 2008 19:19:26 +0000 X-Authority-Analysis: v=1.0 c=1 a=IWnH0euKuzgA:10 a=K8k5FXa3V3kA:10 a=eTv69xBn7nxy7eU9_zAA:9 a=iA3VrI1F9kqgqO3ibAUA:7 a=aUu9kkVP_-y663aX3Qjxxyb6DjEA:4 a=WM6lGTjlpIgA:10 a=WuK_CZDBSqoA:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 80448D7BD2 for ; Fri, 20 Jun 2008 14:19:25 -0500 (CDT) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ivPgp70YkfSH for ; Fri, 20 Jun 2008 14:19:25 -0500 (CDT) Received: by earth.ufp (Postfix, from userid 33) id 5B448D86F8; Fri, 20 Jun 2008 14:19:25 -0500 (CDT) To: internals@lists.php.net MIME-Version: 1.0 Date: Fri, 20 Jun 2008 14:19:25 -0500 Message-ID: <303025b00a328c090e45eff2853a80e0@localhost> X-Sender: larry@garfieldtech.com User-Agent: RoundCube Webmail/0.1b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: larry@garfieldtech.com (Larry Garfield) On Fri, 20 Jun 2008 12:00:07 -0400, Robert Cummings wrote: >> function foo($a, $b, &$c) global ($d, &$e) { >> // ... >> } >> >> $myfunc = lambda($a, $b, &$c) lexical ($d, &$e) { >> // ... >> } >> >> That puts all the information in the declaration line with parallel > syntax and semantics, and would even allow both by-val and by-ref usage > for both lexical and global values. The following would then be exactly > equivalent functionality-wise: >> >> function foo() global (&$a) { >> // ... >> } >> >> function foo() { >> global $a; >> // ... >> } >> >> Is that too crazy an idea? > > I like that, and also like the parenthesis on both parameter listings > for greater readability. In a related question, would the following be a > natural extension? Agreed to it being better with parens than without. > $myfun = lambda($a, $b, &$c) lexical ($d, &$e) global ($f, &$g){ > // ... > } I realized that right after I sent my last email. Yes, that would be the logical implication, and it somewhat parallels class Foo extends Bar implements Baz. It seems if lexical values are going to have both by-val and by-ref uses at all, following the function parameter syntax for it has the lowest wtf factor. I don't see global and $GLOBALS going away any time soon, though. Mind you, I have no idea what the above would do to the engine-level implementation. I would, however, much prefer explicit lexical declaration than implicit. Implicit declaration in a "create variables on demand" language can have some very odd behaviors. For instance, if you have a lambda that is declared in a function and has an internal variable it uses named $foo, and then 6 months later you add a $foo 20 lines up in the calling function, you now have a very strange and difficult bug to track down that won't show up until the lambda is invoked, which could be a long time later. --Larry Garfield