Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46440 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56675 invoked from network); 16 Dec 2009 02:05:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Dec 2009 02:05:44 -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.30.56 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.30.56 qmta06.emeryville.ca.mail.comcast.net Received: from [76.96.30.56] ([76.96.30.56:35433] helo=QMTA06.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 62/93-33900-770482B4 for ; Tue, 15 Dec 2009 21:05:44 -0500 Received: from OMTA12.emeryville.ca.mail.comcast.net ([76.96.30.44]) by QMTA06.emeryville.ca.mail.comcast.net with comcast id HcLN1d0050x6nqcA6e5gG2; Wed, 16 Dec 2009 02:05:40 +0000 Received: from earth.ufp ([98.220.236.211]) by OMTA12.emeryville.ca.mail.comcast.net with comcast id He5f1d0074aLjBW8Ye5gzB; Wed, 16 Dec 2009 02:05:40 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 7E18BD7A50 for ; Tue, 15 Dec 2009 20:05:38 -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 S-+D5OGTK69r for ; Tue, 15 Dec 2009 20:05:38 -0600 (CST) Received: from luna.localnet (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTPSA id 65423D7A15 for ; Tue, 15 Dec 2009 20:05:38 -0600 (CST) To: internals@lists.php.net Date: Tue, 15 Dec 2009 20:05:37 -0600 User-Agent: KMail/1.11.2 (Linux/2.6.27-16-generic; KDE/4.2.2; i686; ; ) References: <4B01A4C2.8030602@gmx.net> <6571303B-82D2-43E4-8550-E2B9420BA241@pooteeweet.org> <4B27E7A4.6030503@gmx.net> In-Reply-To: <4B27E7A4.6030503@gmx.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-ID: <200912152005.37168.larry@garfieldtech.com> Subject: Re: [PHP-DEV] Closures and $this: Please vote! From: larry@garfieldtech.com (Larry Garfield) On Tuesday 15 December 2009 1:46:44 pm Christian Seiler wrote: > Hi Lukas, > > > Call for a vote. This time around people cannot claim to not have had > > time to review the issue. Also back then we tried to play it safe > > because of the short time before we were to release. This time there is > > more time for this to mature if needed inside svn. > > Ok, so then I call for a vote. Again, here are the options: > > (0): No $this in closures, keep it that way. (keep PHP 5.3 behavior) > > (A): Original closures implementation: > $this is always the object context at > closure creation. No possibility to do > $someObject->closureProperty(...) and thus > no possibility to extend objects! > > (C): Javascript-like behaviour: Bind $this only when calling > the closure as object method, else $this is undefined. > > (D): JS-like behaviour on top of (A). > Please look at the RFC as to why I consider it to be a > *REALLY*, *REALLY* bad idea. > > (A+): (A) + Closure::bind & Closure->bindTo for rebinding > if this is wanted & the possibility to call a closure as an object > method. (See last section of RFC for details) > > My vote: (A+) Another non-C-developing PHP coder voting for A+. I like the explicitness of knowing when $this is going to change on me, and it allows for dynamic extension. Regarding the other points noted in the RFC, I believe that when a closure is bound to an object it should have full access to private/protected properties of that object. (I believe that is option 2.) If that is not done, then being able to call $foo->aClosure() is really just syntactic sugar and not especially useful. When cloning an object with a bound closure, my expectation is that it would behave the same way as an object or resource that is a property of the cloned object. I don't know if that makes sense in the context of closures, but that is what my knee-jerk expectation would be. I am not sure we can rely on the __clone() method to handle rebinding the closure. The point of binding closures to an object is so that objects can get extra methods post-creation. How can the __clone() method, which is written pre-creation, know what closures have been bound to it in order to rebind them to the new object? If the developer knows the exact name in advance to rebind, then generally that code could just be a normal method. I don't see how one could logically rebind a closure on __clone(). -- Larry Garfield larry@garfieldtech.com