Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98069 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82311 invoked from network); 31 Jan 2017 11:14:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 31 Jan 2017 11:14:56 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.150 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.150 blu004-omc4s11.hotmail.com Received: from [65.55.111.150] ([65.55.111.150:56170] helo=BLU004-OMC4S11.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/42-51557-EA170985 for ; Tue, 31 Jan 2017 06:14:55 -0500 Received: from BLU436-SMTP45 ([65.55.111.136]) by BLU004-OMC4S11.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 31 Jan 2017 03:14:52 -0800 X-TMN: [qzwSIjb8pUx5jQZqMMqDX+IW5kBvSA+Y] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_101A18C7-6528-4A57-AB90-72A5441E5C6E" MIME-Version: 1.0 (Mac OS X Mail 10.2 \(3259\)) Date: Tue, 31 Jan 2017 12:14:47 +0100 In-Reply-To: <642a72cd-e322-0b22-452f-dfbd521aee02@php.net> CC: PHP internals To: Michael Wallner , Andrea Faulds , php-lists@koalephant.com References: <3F428CA4-8211-44E6-9B60-62ADB47934B3@koalephant.com> <642a72cd-e322-0b22-452f-dfbd521aee02@php.net> X-Mailer: Apple Mail (2.3259) X-OriginalArrivalTime: 31 Jan 2017 11:14:50.0338 (UTC) FILETIME=[3D348420:01D27BB3] Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: bobwei9@hotmail.com (Bob Weinand) --Apple-Mail=_101A18C7-6528-4A57-AB90-72A5441E5C6E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hey, > Am 31.01.2017 um 11:23 schrieb Michael Wallner : >=20 > On 31/01/17 05:53, Stephen Reay wrote: >> Hi Andrea, All, >>=20 >>> On 31 Jan 2017, at 08:12, Andrea Faulds wrote: >>>=20 >>> Is it necessary to introduce a new keyword, fn? >>>=20 >>> I think you'd get a similar benefit from: >>>=20 >>> function($x) =3D> $arr[$x] >>>=20 >>> Likewise, is it necessary to restrict auto-capture to the =3D> >>> syntax? Couldn't we allow the following? >>>=20 >>> function ($x) { >>> return $arr[$x]; >>> } >>>=20 >>=20 >> I agree that the `fn` keyword isn=E2=80=99t really necessary. I=E2=80=99= ve never >> quite understood how arrow functions with implied returns etc are >> supposed to make for *more* readable code, but if they=E2=80=99re = going to be >> part of the language please at least keep some consistency with >> regular closures. >=20 > Yes, I also think that keeping the function keyword would be better. >=20 >>=20 >> In the case that regular closures got auto-capture, would a >> `use($foo, $bar, $baz)` segment on a closure still be honoured (i.e. >> disable auto-capture), and would it have any impact (positive or >> negative) on performance/memory usage? After several years of JS >> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only = inherit the >> variables you explicitly `use()` in closures. >=20 > Wouldn't there be just too many existing closures, which do not use > `use` but (maybe) expect a clean scope? The RFC is exclusively proposing single-expression short Closures. We do NOT want multi-statement short Closures; it is a *feature* that = generic Closures need an "use ($foo, $bar)". This vastly improves readability and debuggability - it basically tells = you whether the variables inside the code are imported or not. As = Stephen Reay notes: >> After several years of JS >> closure =E2=80=98fun=E2=80=99 I kind of like that with PHP you only = inherit the >> variables you explicitly `use()` in closures. So, auto-import for generic Closures definitely isn't an option. Just on short, single-line Closures there is no benefit to "use ()", as = EVERY variable used in the short Closure is supposed to be an imported = variable. There is no point in forcing the user to distinguish between = imported and local variable here. Also, using "fn" in favor of "function" has the advantage of less = clutter in one line. Compare array_map(fn($x) =3D> $x + 1) to array_map(function($x) =3D> $x + 1) The syntactical construction is already pretty clearly showing what's = going on. The "function" keyword itself is already larger than the whole = body. It distracts while reading the actual code. Additionally, using "fn" is optically highlighting the fact that it's a = short-Closure with auto-import and not a normal Closure with explicit = import. Thanks, Bob= --Apple-Mail=_101A18C7-6528-4A57-AB90-72A5441E5C6E--