Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42795 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58311 invoked from network); 23 Jan 2009 06:35:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2009 06:35:20 -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:58947] helo=QMTA06.westchester.pa.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/E0-45130-72569794 for ; Fri, 23 Jan 2009 01:35:19 -0500 Received: from OMTA14.westchester.pa.mail.comcast.net ([76.96.62.60]) by QMTA06.westchester.pa.mail.comcast.net with comcast id 6uFG1b0011HzFnQ56ubH7H; Fri, 23 Jan 2009 06:35:17 +0000 Received: from earth.ufp ([24.13.255.226]) by OMTA14.westchester.pa.mail.comcast.net with comcast id 6ubH1b00A4trKQ83aubHkG; Fri, 23 Jan 2009 06:35:17 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 080D6D7A24 for ; Fri, 23 Jan 2009 00:35:16 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X1v-cIAq6ci7 for ; Fri, 23 Jan 2009 00:35:15 -0600 (CST) Received: from luna.localnet (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTPSA id DB11BD7A16 for ; Fri, 23 Jan 2009 00:35:15 -0600 (CST) To: internals@lists.php.net Date: Fri, 23 Jan 2009 00:35:14 -0600 User-Agent: KMail/1.10.3 (Linux/2.6.27-7-generic; KDE/4.1.3; i686; ; ) References: <1016989528.20090112233204@marcus-boerger.de> <76BB6A71-62B3-4F0F-BB30-89CA7BAF5BD3@pooteeweet.org> <497880E8.5080202@gmx.net> In-Reply-To: <497880E8.5080202@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200901230035.14792.larry@garfieldtech.com> Subject: Re: [PHP-DEV] [RFC] Object extension, $this binding of closures, chat results (was: Re: [PHP-DEV] [RFC] prototyping) From: larry@garfieldtech.com (Larry Garfield) On Thursday 22 January 2009 8:21:28 am Christian Seiler wrote: > Hi everybody, > > We had that chat that Lukas announced yesterday and I promised Lukas to > sum up the results of that chat. > > Problem was: There were only four people really there: Stas, Lukas, > David and me. Lukas was interested in getting results in order to be > able to release PHP 5.3 beta 1, Stas and I basically agreed on > everything and unfortunately David didn't stay long enough in order to > actually have a real discussion. > > I'm not assigning blame here for not coming to anyone, I just wanted to > make clear that we actually couldn't reach a consensus - or well, > rather, Stas and I could but I don't think that's the way it should be. > However, Lukas wants to release 5.3 beta 1 and I can really understand > him that he doesn't want to drag this out infinitely. > > I've written up the results of the discussion I had with Stas in the > Wiki for everyone to read. I hope there's enough structure in it to make > the main points clear. Please read it thoroughly before replying on-list > in order to actually have a constructive dialogue. > > Here it is: IMO, a very large part of the problem is the implicit binding of $this when a closure happens to be defined inside a method of a class. Every other variable that the closure inherits needs to be defined explicitly; that not only helps the parser but helps human readers. Having $this be magically bound seems like a cause for confusion later on down the road. That said, I very much like the proposal given in the RFC. Rebinding of a closure should be an explicit operation that a future reader of the code can visually see and therefore know about. That removes any potential WTFs when $this is suddenly $that even though you didn't mean for it to be. Regarding the details, wherein lives the devil: - If a closure is bound to an object and does NOT make use of $this, do we still want to throw a warning if it is called? In that case the binding is irrelevant anyway. (That goes back to the point about an implicit initial bind, which I am still not convinced is wise.) - IMO, once a closure has been bound to an object, its $this should have all the same access as a method defined literally on that object's class. That is, it should have private/protected access the same as a "normal" method. - I am a little unclear on what the expected cloning behavior is. Do closures have a clone method? Take the following example: class A { function getClosure() { $var = new Foo(); return function() use ($var) { return $var->something; } } } $a = new A; $o = new stdClass(); $closure = $a->getClosure(); $o->foo = $closure->bindTo($o); Now, are $closure->var and $o->foo->var the same object or no? I'm assuming they are from the RFC, but then how do you implement a deep clone of the closure on binding if you need to? -- Larry Garfield larry@garfieldtech.com