Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28434 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35421 invoked by uid 1010); 19 Mar 2007 19:25:22 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 35405 invoked from network); 19 Mar 2007 19:25:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2007 19:25:21 -0000 Authentication-Results: pb1.pair.com header.from=sean@caedmon.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=sean@caedmon.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain caedmon.net from 69.60.120.90 cause and error) X-PHP-List-Original-Sender: sean@caedmon.net X-Host-Fingerprint: 69.60.120.90 iconoclast.caedmon.net Linux 2.4/2.6 Received: from [69.60.120.90] ([69.60.120.90:42132] helo=iconoclast.caedmon.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BB/D8-01604-0A3EEF54 for ; Mon, 19 Mar 2007 14:25:21 -0500 Received: from localhost ([127.0.0.1]) by iconoclast.caedmon.net with esmtp (Exim 3.35 #1 (Debian)) id 1HTNTf-0004HL-00; Mon, 19 Mar 2007 15:25:07 -0400 Message-ID: <45FEE396.7040905@caedmon.net> Date: Mon, 19 Mar 2007 15:25:10 -0400 User-Agent: Thunderbird 1.5.0.9 (X11/20070103) MIME-Version: 1.0 To: Stanislav Malyshev CC: Wez Furlong , internals@lists.php.net References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <45FDF031.4010508@zend.com> <45FE2312.1050506@zend.com> <45FED6D9.8030307@caedmon.net> <45FEDAE5.2010309@zend.com> In-Reply-To: <45FEDAE5.2010309@zend.com> X-Enigmail-Version: 0.94.2.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: sean@caedmon.net (Sean Coates) > If it would create anonymous function compile-time, it would be a big > advantage to Wez's patch because then this function could be cached. > Thinking about this, maybe it is the reason enough to do this even if > it's not real closure. On mulling this over a bit more, other than quick one-off callbacks (which would definitely benefit from avoiding compile on every request), one of the key reasons to use create_function() is actually to create dynamic functions: $fancyVer = create_function('', 'return "PHP " . phpversion();'); // could be optimized as: $fancyVer = create_function('', 'return "PHP ' . phpversion() .'";'); (the latter only calls phpversion() at declaration, not each time the lambda runs) Since phpversion() is available globally, this isn't a problem. But what happens if we want to use a variable, instead? $ver = phpversion(); $fancyVer = create_function('', "return 'PHP $ver';"); // this currently works ^ How would this be rewritten, though? $ver = phpversion(); $fancyVer = function () { return "PHP $ver"; }; where would $ver come from? the parent scope? the lambda's local scope? what if it's defined in both places? S