Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113780 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33676 invoked from network); 25 Mar 2021 16:29:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2021 16:29:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B992B1804B7 for ; Thu, 25 Mar 2021 09:25:43 -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=-0.7 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 25 Mar 2021 09:25:43 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id CA5D75C00F4 for ; Thu, 25 Mar 2021 12:25:41 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Thu, 25 Mar 2021 12:25:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=YH53t9 ncW/zbYIsj1pVPruKOiiMSRuCXUVBhsiNBLSM=; b=JFY34uvmLvRvGzq1YeOSjR 1BzYFk7oPuOyRB7C9lM36pxoc9zgm86vOoNTNTkTwaS5IBtkeKumR+mBHOKVJ4Wn tGlaR9hU0kXZYwvZxB7auJyeSFtVvWE5b1+x4FfUBBTxs+kHQUMf747L9BJnF+2G L82fylunwqLtOGcFP/UWjZdiFDzT7Lzq0hBpLS10p3BePLzEN5T/Xi94Dx9sbPgj VCey2FlA6K19QqQFPwgdslGXIuZEIptVEPpGm2KnifiYRXXnTH7a242lBE4v8XaF UCGpeVeeoVXyVuSe+jm0E30cN6TQEMv5rXpUygVn98rQPxH+BhjLuEeiIUY0osWg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudehtddgkeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeltddtiedvveeglefhieehtddviefffeehhedvkeeu keffffetkeelgfevvdekteenucffohhmrghinhepvgigthgvrhhnrghlshdrihhonecuve hluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhies ghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 6233B3A0842; Thu, 25 Mar 2021 12:25:41 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-273-g8500d2492d-fm-20210323.002-g8500d249 Mime-Version: 1.0 Message-ID: <43a2b198-ab3d-411a-b978-2924e6af4b13@www.fastmail.com> In-Reply-To: References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> Date: Thu, 25 Mar 2021 11:25:21 -0500 To: "php internals" Content-Type: text/plain Subject: =?UTF-8?Q?Re:_[PHP-DEV]_[RFC]_Auto-capture_multi-line_closures_and_short?= =?UTF-8?Q?_functions_take_2?= From: larry@garfieldtech.com ("Larry Garfield") On Thu, Mar 25, 2021, at 12:47 AM, Peter Stalman wrote: > On Wed, Mar 24, 2021 at 10:15 AM Chase Peeler wrote: > > > I guess my one question would be why we didn't support auto-capture when we > > first implemented anonymous functions, and if there was a reason, why does > > that no longer apply? > > > > I believe this was the original discussion: > > https://externals.io/message/38290 > > Thanks, > Peter Thanks! I just skimmed that thread looking for scope discussions. I didn't read everything so I may have missed a comment somewhere, but the gist seems to be: * The original proposal included manual capture because it originally was going to capture everything by reference, not by value, and so it was seen as "safer" to not surprise someone with references leaking about. (Especially comparisons to Javascript.) * There was mention in the thread of there being a performance advantage of manual capture, but I didn't quite follow it. Also, that was back in 5.3 and so much has changed since then in the engine that I would consider any comments about performance from that era no longer relevant. * There was ample debate about what syntax to use for manual capture, but very little discussion of whether it should be manual or automatic in the first place. * In the end, we ended up with the use ($byVal, &$byRef) syntax we have today... but with the switch to by-val by default there was no discussion of whether auto-capture should be used since that was already safer. Arguably the need to differentiate by val or by ref made the explicit list necessary. So in conclusion, it seems the reasons closures weren't auto-capture always were: 1) Possible performance concerns that are no longer relevant. 2) Avoid surprise references. 3) Allow users to capture by value or by reference. Point 1 is no longer relevant as the engine has changed so much. Point 2 is no longer relevant since forever, since capture is by-val by default. Point 3 is only relevant in the cases where you need to capture by reference, which in practice it turns out are really quite rare. So, I would argue that all of the reasons for manual capture in the first place are no longer relevant, except in the edge case where you really do want to capture by reference. Which is exactly what the RFC currently says. :-) --Larry Garfield