'

On Fri, Oct 7, 2011 at 8:58 PM, Gustavo Lopes <glo...@nebm.ist.utl.pt> wrote:
> On Fri, 07 Oct 2011 18:31:42 +0100, Ferenc Kovacs <tyr...@gmail.com> wrote:
>
>> do we have a wiki/documentation about what exactly ended up in 5.4
>> from the Closure improvements? (Rebind)
>>
>> https://wiki.php.net/rfc/closures/object-extension#privateprotected_members_scope
>> is really hard to read, as it contains all of the suggested ideas and
>> possible solutions, etc.
>> if not, maybe someone with the required knowledge  could start working
>> on adding the documentation?
>>
>
> I don't think so, but if I had to summarize the innovations in 5.4, this
> would be it:
>
> - Closures can now have an associated scope
> - Closures can now have a bound object
> - Closures can now be either static or non-static
>
> - Closures defined in a place with an active scope are scoped accordingly
> - Closures defined inside an instance method (or bound closure) have a bound
> object (namely $this)
> - Closures are static if defined within a static method or with the static
> keyword (static function() { ... })
>
> static => !bound
> (but it's false that !static => bound)
> bound => scoped
> !static && scoped => bound
> (i.e., if !static, scoped <=> bound)
>
> The bound instance and the scoped can be freely changed with Closure::bind
> and $closure->bindTo, subject to these constraints.

"- Closures can now have an associated scope"
as it is 
https://wiki.php.net/rfc/closures/object-extension#privateprotected_members_scope
?
at first I thought that scope means Variable scope, but I think I get
it now: it means that when the Closure calls/access something through
$this, it will be handled as it was called/accessed from the given
class(scope).
and this also explains why we had to add the third param for Closure::bind.
the bound param defines what is the $this pointing to, and the scope
means that from what scope would be used for accessing the $this.
having a static Closure means that it won't have the $this, but it can
still have a scope (so it can interact with other static methods).

thanks, I think I managed to wrap my head around that!

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

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

Reply via email to