Re: Re: Closures and __FUNCTION__
| From: | Justin Martin | Date: | Mon, 13 Apr 2009 08:20:00 +0000 |
| Subject: | Re: Re: Closures and __FUNCTION__ | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-43673@lists.php.net to get a copy of this message | ||
I suppose it's an issue of cloning. Perhaps there's some difference
between a cloned closure and a referenced closure?
Thanks,
Justin Martin
Peter Danenberg wrote:
>> First, we define $foo and load it with NULL so that it is available for
>> referencing.
>
> It turns out loading $foo is superfluous; I can get away with just:
>
> $foo = function($foo) use (&$foo) {
> $foo();
> }
>
>> Next, in terms of program logic, we create a closure with a lexical
>> ('use') variable of a reference to $foo, which is then assigned to
>> $foo. Thus, the reference to $foo in the closure declaration now
>> points to the closure itself.
>
> That much is clear; but why $foo is all of the sudden bound within the
> closure when I use by reference (&$foo) as opposed to use by value
> ($foo) is mysterious.