Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114249 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31156 invoked from network); 29 Apr 2021 09:20:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Apr 2021 09:20:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 284E61804F3 for ; Thu, 29 Apr 2021 02:25:25 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from darkcity.gna.ch (darkcity.gna.ch [195.49.47.11]) (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, 29 Apr 2021 02:25:24 -0700 (PDT) Received: from smtpclient.apple (unknown [IPv6:2a02:1205:502d:fa80:a43a:ed26:6b7d:13ca]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 65D29150D097 for ; Thu, 29 Apr 2021 11:25:03 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.80.0.2.43\)) Date: Thu, 29 Apr 2021 11:25:02 +0200 References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> To: PHP Internals In-Reply-To: Message-ID: <85D2BF1C-167F-4D0A-86FD-2ECAC5956192@cschneid.com> X-Mailer: Apple Mail (2.3654.80.0.2.43) Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and short functions take 2 From: cschneid@cschneid.com (Christian Schneider) Am 29.04.2021 um 10:14 schrieb Rowan Tommins : > On 28/04/2021 23:00, Nuno Maduro wrote: > 3) All variables are captured, there is no local scope. This is = effectively what PHP's single-expression closures use. >=20 > Option 3 is the easy option, and is currently "good enough" because = it's rare to need a purely local variable within a single expression. = For a full function body, local variables are much more likely, so we = now need to think about the question more carefully. >=20 > Without a keyword like "var" to declare it, I think most users would = assume that an initialisation like "$foo=3Dnull;" at the top of their = closure would make a variable local. This assumption by the users would be true as we are capturing by value, = not by reference. At the same time it feels like abusing a side-effect. But adding some = sort of explicit local variable declaration seems even worse (as in even = less PHP-like) to me. This illustrates why I'm wary of / opposed to auto-capture for = multi-line closures. - Chris