On Thu, Nov 19, 2009 at 4:29 PM, Jelrik van Hal <jelri...@jelrikvh.nl> wrote:

> Victor, I do wholeheartedly agree with you about the mess things will be
> when allowing $this to refer to different things in different contexts of
> calling the same closure (B, C and D): I think it'll prove very difficult to
> keep track of which call will end up doing exactly what in which
> environment.

I think any mechanism for rebinding $this (whether automagical or
explicit) will be too, well, weird.  I can imagine a system of
rebinding $this being both consistent and useful, but it adds too much
complexity: to understand what's going on, you not only need to
understand closures, but you need to know how they interact with PHP's
OO system, you need to know what rebinding is (it doesn't happen
anywhere else that I can think of), and you need to know how the
rebinding system works.  JavaScript's approach actually fairly
confusing--and this is despite the fact that the language has always
had it.

> Also, I'm wondering why people think there should be a $this inside a
> closure. As stated in the RFC/Wiki, closures are not thought out to be used
> alongside OO-code. Why would we want to couple them? I see the use of
> closures, but not as OO-related tools using $this. What is the problem with
> proposal (0), leaving it as it is now?

I do think it would be nice if function() use ($this) { ... } worked,
and bound $this in the same way that it bound any other variable,
instead of producing "Cannot use $this as lexical variable".  This
would eliminate the need to do:

$obj = $this;
$fn = function() use ($obj) {
  // use $obj as if it were $this
}

Was this how things used to work, before

http://wiki.php.net/rfc/closures/removal-of-this

happened?




Michael

-- 
http://beebo.org

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

Reply via email to