Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98094 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39467 invoked from network); 31 Jan 2017 21:18:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 21:18:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.176 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.176 blu004-omc4s37.hotmail.com Received: from [65.55.111.176] ([65.55.111.176:60499] helo=BLU004-OMC4S37.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 13/1C-51557-D3FF0985 for ; Tue, 31 Jan 2017 16:18:54 -0500 Received: from BLU436-SMTP150 ([65.55.111.135]) by BLU004-OMC4S37.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 31 Jan 2017 13:18:51 -0800 X-TMN: [m7TzbhvkVVBOVlVwKaW45OuXTRM5Mtlg] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 (Mac OS X Mail 10.1 \(3251\)) In-Reply-To: Date: Tue, 31 Jan 2017 22:18:45 +0100 CC: internals@lists.php.net Content-Transfer-Encoding: quoted-printable References: <3F428CA4-8211-44E6-9B60-62ADB47934B3@koalephant.com> <5bfde844-beee-0f15-1f92-f77607f70ae6@mabe.berlin> To: Andrea Faulds X-Mailer: Apple Mail (2.3251) X-OriginalArrivalTime: 31 Jan 2017 21:18:47.0992 (UTC) FILETIME=[9C87B380:01D27C07] Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: bobwei9@hotmail.com (Bob Weinand) > Am 31.01.2017 um 21:45 schrieb Andrea Faulds : >=20 > Hi Marc, >=20 > Marc Bennewitz wrote: >> - Also I like the "use" keyword you have to define your variables >>=20 >> -> Would it be helpful to allow "function () use (*) {}" to inline >> all available variables? >=20 > I did think of that, but it's not as concise as not having to specify = `use` at all. You could take the opposite approach and auto-capture by = default, but permit `use ()` to capture nothing, alongside regular `use = (...)` for explicit capture of variables. >=20 > Thanks. >=20 > --=20 > Andrea Faulds > https://ajf.me/ Hey Andrea, you realize that you are actually proposing quite a heavy BC break? Any code which uses the same variable than in parent scope and does not = overwrite it before its first usage will break. E.g.: $foo =3D [1,2,3]; // more code working on foo doSomeAction(function($bar) { // waaah, $foo is now [1,2,3] instead of null foreach ($bar as $x) { $foo[] =3D $x; } return $foo; }); Or what I have seen in real code: $response_text =3D "Do action"; store_response($response_text); // much later doSomeAction(function() { $response_text .=3D "Do other action"; // Note that accidental .=3D = instead of =3D store_response($response_text); }); The code still works as expected, because things are NULL-initialized = currently. Now with implicit auto-capture this is breaking. No ahead of time errors = like parse or compile errors, which warn you. Just subtly breaking. = Depending on where it's done, it may not be even noticed soon (variables = with the same name at different places tend to have compatible types), = just misbehave subtly. This is not acceptable. Now, when you suggest "function($bar) use (*) =3D> $foo + $bar", I feel = like half the point of the RFC, the conciseness of the syntax, is = missed. And I'd also reject function($bar) =3D> $foo + $bar as this would mean = the "function" keyword introducing different semantics depending on what = follows. [apart from being still not as concise as "fn"] Thanks, Bob=