Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117908 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72690 invoked from network); 12 Jun 2022 00:14:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2022 00:14:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AC76A1801FD for ; Sat, 11 Jun 2022 19:01:50 -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)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 11 Jun 2022 19:01:50 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 450355C0081 for ; Sat, 11 Jun 2022 22:01:50 -0400 (EDT) Received: from imap52 ([10.202.2.102]) by compute1.internal (MEProxy); Sat, 11 Jun 2022 22:01:50 -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=1654999310; x= 1655085710; bh=3mJ4aaj/XxzMhk4iwlv26XHpxcEISzGLUIQXiYCRhiY=; b=L tXi3cqvdd5UO8pxTvvQZdagomV25jxdNd+OLljDKxuCxgK4ktxOp/F4nbMR3L1VZ rUYRVwvr6p2jClQ1rwzCuDYHXgQRqYDu++9pttVBmFU1eMxUi+f9oeMIW8Cgk6t4 BtOWFP6UtFbsOd40UCbNlWDxcopv73szxK304FeErVWRlsE8/eGNoDbqHSqXMXzJ s4aLnGWVJiP8fEqfQ6+puYjwhmAmQszzucuxaswrrMEICePSxf56QFuNxSAYdgW6 I79qTcTPoeOqmESXU2zNf1BQWPTKiom89/Qpf2viTGHFxXIlOTAd1Vn0VAPCBh7o 0Babx+frfSrZhxqGI0RsA== 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=1654999310; x=1655085710; bh=3mJ4aaj/XxzMhk4iwlv26XHpxcEI SzGLUIQXiYCRhiY=; b=P+o7WpFWGk5x9yT6m2QCl+GVJHnS1X+xrhrsWUusYumT OYmhMO8fUay/WBmaaULZy4J9q5IPmB+BQGdEuG3X9+hkupeA8ORpu551lnLeSwgu CKHfHe/TZ1CP5Rp8BIirMPleBNxSu7VMRAO6PejmiE7rdox0i04N8T8n0cln4PLD y40XDN5iCkPcqBXee+jlxRpVGaL56df9xLCr83Ut/4Kv9D9Rk5DjUBHAKhl1UgD5 /xahhpKnZq13wyNspH2dzre046/kEDuIhGsWSA5PXwBeNnuXF/L1X3huuJiHmrkp kqMBa4zaqMfKwPoouZMml2mWk1BE3N2CUijvVFATLA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddugedggeehucetufdoteggodetrfdotf 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 01C5EC6008A; Sat, 11 Jun 2022 22:01:49 -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: In-Reply-To: <8310f3fd-0011-970e-5379-b2b6e03942b2@gmail.com> References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <8310f3fd-0011-970e-5379-b2b6e03942b2@gmail.com> Date: Sat, 11 Jun 2022 21:01:29 -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 4: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 > > > First of all, thanks to all three of you for the work on this. Although > I'm not quite convinced yet, I know a lot of people have expressed > desire for this feature over the years. > To go back to the point about variable scope: right now, if you're in a > function, all variables are scoped to that function. With a tiny handful > of exceptions (e.g. superglobals), access to variables from any other > scope is always explicit - via parameters, "global", "use", "$this", and > so on. If we think that should change, we should make that decision > explicitly, not treat it as a side-effect of syntax. > > I don't find the comparison to a foreach loop very convincing. Loops are > still only accessing variables while the function is running, not saving > them to be used at some indeterminate later time. And users don't "learn > to recognize" that a loop doesn't hide all variables from the parent > scope; it would be very peculiar if it did. There are languages that do, however. Some languages have block-scoped variables by default (such as Rust), or partially blocked scoped depending on details. PHP is not one of them, but to someone coming from a language that does, PHP's way of doing things is just as weird and requires learning. The point here is that "which things create a scope and which don't" are not "intuitive" in any language. They're always language-idiomatic, and may or may not be internally consistent, which is the important part. PHP is fairly internally consistent: functions and classes create a scope, nothing else does. This RFC doesn't change that one way or another, so it's not really any harder to learn. Plus, as noted, the `fn` keyword becomes consistently the flag saying "auto-capture happens here, FYI", which is already the case as of 7.4. > Which leads me back to my constructive suggestion: let's introduce a > block scoping syntax (e.g. "let $foo;") as a useful feature in its own > right, before we introduce short closures. > > As proposed, users will need to have some idea of what "live variable > analysis" means, or add dummy assignments, if they want to be sure a > variable is actually local. With a block scoping keyword, they can mark > local variables explicitly, as they would in other languages. That may be a useful feature on its own, especially for longer loops. I'm definitely open to discussing that. I don't think that is a prerequisite for a nicer lambda syntax, however, as I don't think the confusion potential is anywhere near as large as you apparently fear it is. --Larry Garfield