Re: Re: Closures and __FUNCTION__

From: Date: Mon, 13 Apr 2009 08:09:00 +0000
Subject: Re: Re: Closures and __FUNCTION__
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-43671@lists.php.net to get a copy of this message
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 the closure declaration now points to the closure itself. Recursion is always complicated :P Thanks, Justin Martin Peter Danenberg wrote: > 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 it, nonetheless.

« previous php.internals (#43671) next »