Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28483 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42554 invoked by uid 1010); 20 Mar 2007 14:24:40 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 42538 invoked from network); 20 Mar 2007 14:24:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Mar 2007 14:24:40 -0000 X-Host-Fingerprint: 147.229.212.212 a03-0106a.kn.vutbr.cz Received: from [147.229.212.212] ([147.229.212.212:2762] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/CA-61497-5AEEFF54 for ; Tue, 20 Mar 2007 09:24:37 -0500 Message-ID: To: internals@lists.php.net Date: Tue, 20 Mar 2007 15:24:32 +0100 User-Agent: Thunderbird 1.5.0.10 (X11/20070313) MIME-Version: 1.0 References: <86478A67-DCA2-4000-9EF0-DA4338E8389B@omniti.com> <54922.216.230.84.67.1174335655.squirrel@www.l-i-e.com> <1174336517.24632.111.camel@blobule> <45474.216.230.84.67.1174337937.squirrel@www.l-i-e.com> In-Reply-To: <45474.216.230.84.67.1174337937.squirrel@www.l-i-e.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 147.229.212.212 Subject: Re: [PHP-DEV] PATCH: anonymous functions in PHP From: daniel@rozsnyo.com (Daniel Rozsnyo) Richard Lynch wrote: > On Mon, March 19, 2007 3:35 pm, Robert Cummings wrote: >> On Mon, 2007-03-19 at 15:20 -0500, Richard Lynch wrote: >>> On Sun, March 18, 2007 6:41 pm, Wez Furlong wrote: >>>> We've been daydreaming about the ability to do something like this >>> in >>>> PHP: >>>> >>>> $data = array("zoo", "orange", "car", "lemon", "apple"); >>>> usort($data, function($a, $b) { return strcmp($a, $b); }); >>>> var_dump($data); # data is sorted alphabetically >>> I'd LOVE it if there was SOME difference between this and a normal >>> 'function' definition... >>> >>> I guess we're kind of stuck with 'create_function' being the mess >>> that >>> it is. >>> >>> But perhaps something like 'temp_function' or 'local_function' or >>> 'lexical_closure' or something similar. Even 'horse' [*] would be >>> fine by me. >>> >>> I think it muddies things too much to have it just be 'function' >>> with >>> no name after it. >>> >>> +1 >> A function with a name is no longer anonymous ;) > > I am not suggesting that there be a name. > > I am suggesting that the reserved keyword for an anonymous function > should not be 'function', the same as a normal function. > I don't have anything against 'function', I think JS uses the same syntax - function without a name. If you change it to something different, e.g 'callback', then you loose the information that it is actually a function $error_func = callback($msg) { file_put_contents('php://stderr',"Error: $msg\n"); } vs. $error_func = function($msg) { file_put_contents('php://stderr',"Error: $msg\n"); } The second one looks better for me.