Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:38308 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27360 invoked from network); 17 Jun 2008 03:57:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jun 2008 03:57:29 -0000 Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.62.48 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.62.48 qmta05.westchester.pa.mail.comcast.net Received: from [76.96.62.48] ([76.96.62.48:40369] helo=QMTA05.westchester.pa.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/56-18128-82637584 for ; Mon, 16 Jun 2008 23:57:29 -0400 Received: from OMTA04.westchester.pa.mail.comcast.net ([76.96.62.35]) by QMTA05.westchester.pa.mail.comcast.net with comcast id ebBY1Z0020ldTLk5512T00; Tue, 17 Jun 2008 03:57:26 +0000 Received: from earth.ufp ([24.13.255.226]) by OMTA04.westchester.pa.mail.comcast.net with comcast id erxR1Z00E4trKQ83QrxSLv; Tue, 17 Jun 2008 03:57:26 +0000 X-Authority-Analysis: v=1.0 c=1 a=IWnH0euKuzgA:10 a=K8k5FXa3V3kA:10 a=67BIL_jfAAAA:8 a=9jrseXc8YzFxtuv9bIoA:9 a=u6gLjSUvYMYwGd83rHYA:7 a=p80Vp668VsK-v9ybHTahEBFQe3UA:4 a=FHBbIDN7CdwA:10 a=XF7b4UCPwd8A:10 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id CD9F3D86E0 for ; Mon, 16 Jun 2008 22:57: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 W8EDv-5599TZ for ; Mon, 16 Jun 2008 22:57:25 -0500 (CDT) Received: from vulcan (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTP id A0AD5D86DE for ; Mon, 16 Jun 2008 22:57:25 -0500 (CDT) To: internals@lists.php.net Date: Mon, 16 Jun 2008 22:57:23 -0500 User-Agent: KMail/1.9.6 (enterprise 0.20070907.709405) References: <4856A547.3080801@gmx.net> <4856B752.1040500@gmx.net> In-Reply-To: <4856B752.1040500@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200806162257.24141.larry@garfieldtech.com> Subject: Re: [PHP-DEV] [PATCH] [RFC] Closures and lambda functions in PHP From: larry@garfieldtech.com (Larry Garfield) Thoughts from a user-land denizen: - I conceptually really like. lambdas and closures are a feature I've been jealous of Javascript for having since I learned how Javascript "really" worked. :-) - I recall earlier discussion pondering if we should be using the keyword "function" to describe this new construct. It is a function, but not as we know it. (Thank you, Mr. Spock.) Should we consider using the keyword "lambda" instead, or do we think re-using "function" is acceptable? (I'm cool either way; I just wanted to make sure it was a conscious decision.) - I don't think the lexical keyword is a wtf at all, especially given that it works essentially like global. It simplifies both the internal code and the user-space code, because it becomes more self-documenting. The semi-colon is a slight wtf, but since it is the same as Javascript I think most people will get used to it. I have no objection to it. - I am a little confused about the OOP interaction. How does a function become a public method of the class? class Example { private $a = 2; function myMethod($b) { $lambda = function() { lexical $b; return $this->a * $b; // This part I get }; return $lambda; } } $e = new Example(); $lambda = $e->myMethod(); $e->$lambda(5); That doesn't seem right at all, but that's how I interpret "Essentially, closures inside methods are added as public methods to the class that contains the original method." Can you give an example of what that actually means? - Related to that, would it then be possible to add methods to a class at runtime using lambda functions as the added methods? If so, how? If not, is that something that could reasonably be added here without hosing performance (or at least doing so less than stacking __call() and call_user_func_array() does)? I guess I just need some code examples to see how this behaves in relation to objects, because I'm not really following it as is. - My minuscule knowledge of the engine internals looks at the description there and doesn't see anything to be scared about, but I am far from an authority in that subject. It does seem to side-step the "can't compile at compile time" problem that was raised back in December, which is good. Overall, big +1 pending clarification of how lambdas and classes interact, which I still don't grok. On Monday 16 June 2008, Christian Seiler wrote: > Hi, > > Lukas Kahwe Smith asked me to put my proposal into the PHP wiki, which I > have done: > > http://wiki.php.net/rfc/closures > > I also have incorporated the last comment by troels knak-nielsen about > JS behaving the same way as my patch and thus not being that much of a > WTF at all (I somehow had a different behaviour for JS in mind, I > probably got confused with yet another language). > > Anyway, feel free to comment. > > Regards, > Christian -- Larry Garfield AIM: LOLG42 larry@garfieldtech.com ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson