Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43678 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 32815 invoked from network); 13 Apr 2009 18:10:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Apr 2009 18:10:42 -0000 X-Host-Fingerprint: 83.6.249.254 abdh254.neoplus.adsl.tpnet.pl Received: from [83.6.249.254] ([83.6.249.254:3091] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DB/95-22673-F1083E94 for ; Mon, 13 Apr 2009 14:10:41 -0400 Message-ID: To: internals@lists.php.net Date: Mon, 13 Apr 2009 20:10:29 +0200 User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 References: <20090412025100.GA5493@klutometis.wikitex.org> <8B.71.31755.246E2E94@pb1.pair.com> <20090413080352.GA10458@klutometis.wikitex.org> In-Reply-To: <20090413080352.GA10458@klutometis.wikitex.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 83.6.249.254 Subject: Re: [PHP-DEV] Re: Closures and __FUNCTION__ From: m.kurzyna@crystalpoint.pl (Marcin Kurzyna) 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) { > if ($n == 1) > return 1; > else > return $n * $factorial($n - 1); > }; > > print $factorial(3); > > and eventually "PHP Fatal error: Function name must be a string." This is correct. See: in the first example you were referencing previously defined $foo (which at the moment of first reference was NULL). It was only later replaces with closure itself but it worked because of the reference. On the other hand when you copy variable you try to use undefined $factorial (thus the notice). It is because at the moment of "using" the variable it's undefined. Only later it becomes our closure, however then it's after evaluation of use. Although this is probably more a generals topic. The lack of __FUNCTION__ inside the closure is however something i'd like to hear more about. Any word on this from the devs? TIA, Marcin