Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65963 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85159 invoked from network); 19 Feb 2013 16:28:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2013 16:28:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=florinpatan@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=florinpatan@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.173 as permitted sender) X-PHP-List-Original-Sender: florinpatan@gmail.com X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:43205] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1D/BC-17768-128A3215 for ; Tue, 19 Feb 2013 11:28:17 -0500 Received: by mail-ob0-f173.google.com with SMTP id dn14so6854675obc.32 for ; Tue, 19 Feb 2013 08:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=QS1M8zbDbIA7nwN2ddX7rqKx/B4J774g1JODuK9ZvVw=; b=kg6DCwmRkrLbjHEkrXkzN0tgWCP/iLpTxmv/vJ5RDYI8rNAmQbSR0x7X1r1VSMSHk/ OBrCOhYqzn1k/Rtmq7AtrbFbjQvV+W6PsgY9kzYC7V32uIm7PSvrK1wbAmnLrSqlMsO7 JGmzgLA8ZyxwuPdgyLEwMwkXSJaxiRt4klIE+MxIeEH1jxXxpnOxi20yY4RUAJlzlTGz 8QlpgE44EmiOGAmCVqFpLtJ8eWrYleWt1PC3MfnXFaBlHpqihpVcD13gANyn+PaCSFaO 1pKZIMM+PQJ7ZRHlt/dRElxuW0bATI5Bbjwkt2APY1qe4CJ+DvwOeQBYdq1WCYXtn/+q Wf7w== X-Received: by 10.60.26.231 with SMTP id o7mr3977352oeg.107.1361291294819; Tue, 19 Feb 2013 08:28:14 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.169.3 with HTTP; Tue, 19 Feb 2013 08:27:43 -0800 (PST) In-Reply-To: References: <8490FC41-2696-4948-83A1-3931674183B0@gmail.com> Date: Tue, 19 Feb 2013 18:27:43 +0200 Message-ID: To: Levi Morrison Cc: Marcello Duarte , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Short syntax for anonymous functions From: florinpatan@gmail.com (Florin Razvan Patan) Hello, On Tue, Feb 19, 2013 at 6:09 PM, Levi Morrison wrote: > There's already been an overwhelming negative reaction to this > particular proposed syntax so I won't belabor the point much. In > short, this is too similar to block statements and does have BC > issues. > > -- > > IF (and I stress if) we add a a shorter anonymous function syntax I'd > like it to be geared towards one-liners because that's where the > current syntax feels really verbose, especially when you close over > other variables: > > function ($n) use ($m) { return $m * $n; } > > Versus one potential option: > > ($value) |$m| => $m * $n; > > This syntax is short and expressive at the expense of clarity. > Basically all short-syntax has that trade-off, so I am personally fine > with it. The only other potential problem I see is parsing it; someone > more familiar with PHP's parser would have to verify whether that > would be a problem. > I think that before we establish a syntax for this we should see if there's a real need for this feature, and after that, get a syntax to implement the feature. Say we agree on the syntax above > ($n) |$m| => $m * $n; What happens when my one liner function needs to do one more operation like checking the value of $n before multiplication? I'd rather see a proposal to drop the 'function' keyword from the classes methods and only leave the visibility scope and method name, but for anonymous functions like this one I'd rather keep the 'function' keyword in order to have better visibility when I'm doing a code review/scan new code in a library. What do you think? ---- Florin Patan https://github.com/dlsniper