Peter Danenberg pisze:
Quoth Justin Martin on Pungenday, the 30th of Discord:
If I recall correctly, you can use the 'use' keyword.
Thanks, Justin; that occurred to me, too. But the following results in
"Notice: Undefined variable: factorial":
$factorial = function($n) use ($factorial) {
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 superflu
> 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') va
Well, it's a rather simple bit of logic.
First, we define $foo and load it with NULL so that it is available for
referencing. 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
Quoth Justin Martin on Pungenday, the 30th of Discord:
> Apparently it works as such:
>
> $foo = NULL;
> $foo = function($foo) use (&$foo) {
> ...
> }
>
> Still rather hackish, but better than globals I suppose?
Heh; amazing. I'm not going to pretend to comprehend this hack; but
I'll use i
Quoth Justin Martin on Pungenday, the 30th of Discord:
> If I recall correctly, you can use the 'use' keyword.
Thanks, Justin; that occurred to me, too. But the following results in
"Notice: Undefined variable: factorial":
$factorial = function($n) use ($factorial) {
if ($n == 1)
In addendum I'd like to correct the syntax that I had someone in IRC test.
Apparently it works as such:
$foo = NULL;
$foo = function($foo) use (&$foo) {
...
}
Still rather hackish, but better than globals I suppose?
Thanks,
Justin Martin
Justin Martin wrote:
> Hi Peter,
>
> If I recal
Hi Peter,
If I recall correctly, you can use the 'use' keyword.
$factorial = function($foo) use ($factorial) {
$factorial($foo);
}
$factorial('Hello World!');
I'm still having issues compiling 5.3 on my system, so I haven't tested
this.
Thanks,
Justin Martin
Peter Danenberg wrote:
> T