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: <http://wiki.php.net/rfc/closures/object-extension>
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
[email protected]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php