Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:47041 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30432 invoked from network); 24 Feb 2010 05:47:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2010 05:47:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 76.96.27.228 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 76.96.27.228 qmta15.emeryville.ca.mail.comcast.net Received: from [76.96.27.228] ([76.96.27.228:58512] helo=qmta15.emeryville.ca.mail.comcast.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/D5-26388-67DB48B4 for ; Wed, 24 Feb 2010 00:47:35 -0500 Received: from omta12.emeryville.ca.mail.comcast.net ([76.96.30.44]) by qmta15.emeryville.ca.mail.comcast.net with comcast id lgui1d0090x6nqcAFhnYvD; Wed, 24 Feb 2010 05:47:32 +0000 Received: from earth.ufp ([98.220.236.211]) by omta12.emeryville.ca.mail.comcast.net with comcast id lhnX1d0044aLjBW8YhnXpV; Wed, 24 Feb 2010 05:47:32 +0000 Received: from localhost (localhost [127.0.0.1]) by earth.ufp (Postfix) with ESMTP id 260D1D7A5B for ; Tue, 23 Feb 2010 23:47:30 -0600 (CST) Received: from earth.ufp ([127.0.0.1]) by localhost (earth.ufp [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PfNPBgeoFOYW for ; Tue, 23 Feb 2010 23:47:30 -0600 (CST) Received: from luna.localnet (unknown [192.168.42.1]) by earth.ufp (Postfix) with ESMTPSA id 01B3DD79E7 for ; Tue, 23 Feb 2010 23:47:29 -0600 (CST) To: internals@lists.php.net Date: Tue, 23 Feb 2010 23:47:28 -0600 User-Agent: KMail/1.12.2 (Linux/2.6.31-19-generic; KDE/4.3.2; x86_64; ; ) References: <4B54FC87.8070106@zend.com> <4B844DBA.4050804@zend.com> <4B845E0C.7040005@gmail.com> In-Reply-To: <4B845E0C.7040005@gmail.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-ID: <201002232347.28844.larry@garfieldtech.com> Subject: Re: [PHP-DEV] On closures and lamdba From: larry@garfieldtech.com (Larry Garfield) On Tuesday 23 February 2010 05:00:28 pm Ionut G. Stan wrote: > > This is not entirely correct, you are right. There's a difference > > between anonymous function and closure, though in practice in PHP > > anonymous functions are closures (though some of them are rather trivial > > ones with no variables to "close over") and that's now the only way to > > do closure in PHP (i.e. you can't have non-anonymous closure function). > > Correct me if I'm wrong, but given the fact that PHP only* supports > functions defined in the global space**, with the additional ability to > import global variables using the global statement, wouldn't that make > named functions able to close-over global variables? > > And, if the above is true, wouldn't it be consistent to support the use > statement on named functions, and then deprecate the global statement? > > I remember one of the first implementation for closure, used a statement > similar to global for closing over variables (the lexical statement). IMO, globals could and should use a similar syntax to lexical closures: function foo($a, &$b) global ($c, &$d) { // ... } That would allow a parallel syntax, and allow for both by-value and by- reference globals, which currently we cannot do. And closures/lambdas could/should support the same syntax for globals. --Larry Garfield