Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117907 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71110 invoked from network); 12 Jun 2022 00:07:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2022 00:07:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8A3A21801FD for ; Sat, 11 Jun 2022 18:53:52 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 11 Jun 2022 18:53:51 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 8B93D5C00A5 for ; Sat, 11 Jun 2022 21:53:51 -0400 (EDT) Received: from imap52 ([10.202.2.102]) by compute1.internal (MEProxy); Sat, 11 Jun 2022 21:53:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1654998831; x= 1655085231; bh=mbdGZRkavgkSmyzYpd0EuYqGDNmKipSNW+b+CTxXliI=; b=l Oc5sH+RdgGwzXHQ2tlebOdTiPaQj8EcKClSV817pjTmC2IlVgL0V8LEgvJPfc7dE tMixOxPwQxy3jxG0q3VnYrszD2EqyfKfxBYw9ORVovVCLefFxEGZtlKOZUDqHvxR eQS00ZKwWCWXkLP3me2Ov4QpPq+v/IVMvsEbRxZivctENJfhFle2Jipri9C0cwZA qi4W1JUN2d3+ZVDAx2PRpyhxEHmdOG7ei7GqMDakeouN2Ja1Bw3mD4z0fGiOM9TD HAreZqgi+BemTTuLlT9a65+fc/Cole1ggi/2DrzR9rM675LcC8MJ8tOrNt0Tc/4F R6kBdZ4dsCFONal/YyhRg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1654998831; x=1655085231; bh=mbdGZRkavgkSmyzYpd0EuYqGDNmK ipSNW+b+CTxXliI=; b=ci1cXFmV6fBj1rZWDFtAySXAX2QShqgD+8w892wPHF3M u6/QoTt1RXBwGeuOxUvu4LKjmt7YUn4E14HkTWbhT6lnngy/R44L67EA0MKWU21C CSicCmv2ZBe5dFb6ioKOO0LFTWdUFxhrNcZO9pferV+wPDO32m4lqZM0G2015/46 PSykBujGYbGNP/G2NppbuhN25E3KbMMzsFZqLurILY4vHGya7YK50y83ds042XM+ 8wwYyul6tpxW+oSlDmqgjGlFI0YjDcuw+Za7RF5U40ORgC46yCJb32YqZxcitSqi WieXkZ6IiL//qCvcXeFwv8hyUj9M9aU4BIfuceSLZg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddugedggeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeevheehvdevjeelvdevgfelvefftdejkeelvdekgeeh fffgiedvjefhhfeltdduteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhi vghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0FDA9C6008A; Sat, 11 Jun 2022 21:53:50 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-692-gb287c361f5-fm-20220603.003-gb287c361 Mime-Version: 1.0 Message-ID: <487c86cf-60c0-438f-b630-e698ee1540f2@www.fastmail.com> In-Reply-To: References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <8310f3fd-0011-970e-5379-b2b6e03942b2@gmail.com> Date: Sat, 11 Jun 2022 20:53:30 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: larry@garfieldtech.com ("Larry Garfield") On Sat, Jun 11, 2022, at 5:01 PM, Deleu wrote: > On Sat, Jun 11, 2022 at 11:14 PM Rowan Tommins > wrote: > >> On 09/06/2022 17:34, Larry Garfield wrote: >> > Last year, Nuno Maduro and I put together an RFC for combining the >> multi-line capabilities of long-closures with the auto-capture compactness >> of short-closures ... Arnaud Le Blanc has now picked up the flag with an >> improved implementation ... The RFC has therefore been overhauled >> accordingly and is now ready for consideration. >> > >> > https://wiki.php.net/rfc/auto-capture-closure >> >> >> They may sound like the same thing, but to me "short closure syntax" >> (and a lot of the current RFC) implies that the new syntax is better for >> nearly all closures, and that once it is introduced, the old syntax >> would only really be there for compatibility - similar to how the [] >> syntax replaces array() and list(). If that is the aim, it's not enough >> to assert that "the majority" of closures are very short; the syntax >> should stand up even when used for, say, a middleware handler in a >> micro-framework. As such, I think we need additional features to opt >> back out of capturing, and explicitly mark function- or block-scoped >> variables. >> > > The RFC does mention that the existing Anonymous Function Syntax remains > untouched and will not be deprecated. Whether the new syntax is better for > nearly all closures will be a personal choice. If the new syntax doesn't > suit, say, a middleware handler, then we still can: > - reach for the old syntax > - use invocable classes > - call another method or function which creates a brand new scope and then > returns a function/callable. Correct. If this RFC passes, there will be three equally supported syntaxes for creating closures: function ($a) use ($b) { return $a * $b; }; fn ($a) => $a * $b; fn ($a) { return $a * $b; }; Which one is appropriate in a given situation is left up to developer judgement. My own personal position would be * use fn => where possible * use fn {} if going mult-line. * if the body of the closure is more than ~3 lines and is not virtually the entire wrapping scope, it should be its own named function/method *anyway*, and the new first-class-callable syntax makes that nice and easy to use. That is, I would probably not use the manual-capture syntax very often at all. However, if someone disagrees with me on case 3 it's still there for them if that's easier in context. Whether the new syntax is viewed as "adding auto-capture to long closures" or "adding multi-line support to short closures" is, in the end, a mostly academic distinction with no practical difference. The resulting syntax is smack in the middle of the two existing ones. The original RFC from a year ago approached it from the perspective of the first; The rewritten RFC leans on the second perspective. The use of both names is mostly a historical artifact of reusing the old URL. :-) The net result is the same. --Larry Garfield