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
la...@garfieldtech.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to