Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117909 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94120 invoked from network); 12 Jun 2022 06:46:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2022 06:46:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DDF631801FD for ; Sun, 12 Jun 2022 01:33:06 -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,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 ; Sun, 12 Jun 2022 01:33:06 -0700 (PDT) Received: by mail-qk1-f169.google.com with SMTP id c83so2157159qke.3 for ; Sun, 12 Jun 2022 01:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20210112.gappssmtp.com; s=20210112; h=from:mime-version:subject:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qI1/UncBf9wSNTUszx9oOC+5CeqnQGJ8Q60iZr+AWP8=; b=z5m8jLuGhD2J8OrFE7os7JTXRiVYyQJDMQg2TxZSxt82XDH5mddfn0IdY/G6n683UD CCpw0vFHqMpXDlt5X7RlnN5He0/5oEk78cSQkiop4H6AWIurqAEitKYDSH9Q8u0zHit+ rbCCCliBVjoJDudcJzSUofWXrpR/7ag5gsbdTR/MBLSwaMu9IoyhxwlFQUCjMSgf0LNF Zccp+hbcHsQbTt7azzeC2J9j6ki/0WftLMTk6q9LSRkADUFw8bSyKLEKpk2+gdqN0yui 4+I8Q0wLSlJTTPDxjRbz3+3UR2RZQNM4xjsMCNaA/q2FG3Ip8Ja34BPwEM8aPUMIBuzG VbfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:mime-version:subject:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qI1/UncBf9wSNTUszx9oOC+5CeqnQGJ8Q60iZr+AWP8=; b=Txu/MUWHZxky8DOceqqLdYGBlHDYlIdEybD8+kmw2UEsHhmGKTcxqtjyhue/KF8ipO CIRi2OPS/HG2tFWGtjWmwFfpXQASWXISua2pP89QYOvWWWENm82XX07p0yXjHo8RRJk6 tCNC3ONUdhbfh+0EUKIk4ZaNF5xnviaJjYcfX+amID67wotBtxl685NkHRlyYLj4MvLi PlyaSl3V1t9kVTaBBkjVTZsZHAJYtmIrYBfX+eh0L3frM8xK3gjLvy0sOwpEf+PF741J 0DNlbczVP9lsqBz+aSc+jqUD6SPpBsYzeykeolIAYox7jQUwAa0DJ/yB3X1xINDou2eT 0xbw== X-Gm-Message-State: AOAM533Vk0+EteoJtn+4qNSsOAfpIHChPgxvf2ULf0Oxt+y1p+k3E3Te MSlksW6v97HaEpTZ8MXBFqUvqtbUVq0JmA== X-Google-Smtp-Source: ABdhPJwhA+gQFWht+wd15e4T2wB7+oXu76K1tVFYjZyZH8LnVDQKvp/sJcCNp8aEKaL++19r/z2WWA== X-Received: by 2002:a05:620a:460f:b0:6a7:78fd:bf7e with SMTP id br15-20020a05620a460f00b006a778fdbf7emr2820074qkb.359.1655022785690; Sun, 12 Jun 2022 01:33:05 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id q20-20020a05620a0d9400b006a736c8ea80sm3556638qkl.48.2022.06.12.01.33.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Jun 2022 01:33:04 -0700 (PDT) X-Google-Original-From: MKS Archive Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) In-Reply-To: Date: Sun, 12 Jun 2022 04:33:03 -0400 Cc: Larry Garfield , Rowan Tommins Content-Transfer-Encoding: quoted-printable Message-ID: <56E24B6F-E29D-41D3-8CF0-B1EBC0DECDB2@gmail.com> References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <8310f3fd-0011-970e-5379-b2b6e03942b2@gmail.com> To: php internals X-Mailer: Apple Mail (2.3608.120.23.2.7) Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: mike@newclarity.net (MKS Archive) > On Jun 11, 2022, at 10:01 PM, Larry Garfield = wrote: >=20 > 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. >>>=20 >>> https://wiki.php.net/rfc/auto-capture-closure >>=20 >>=20 >> First of all, thanks to all three of you for the work on this. = Although=20 >> I'm not quite convinced yet, I know a lot of people have expressed=20 >> desire for this feature over the years. >=20 >> To go back to the point about variable scope: right now, if you're in = a=20 >> function, all variables are scoped to that function. With a tiny = handful=20 >> of exceptions (e.g. superglobals), access to variables from any other=20= >> scope is always explicit - via parameters, "global", "use", "$this", = and=20 >> so on. If we think that should change, we should make that decision=20= >> explicitly, not treat it as a side-effect of syntax. >>=20 >> I don't find the comparison to a foreach loop very convincing. Loops = are=20 >> still only accessing variables while the function is running, not = saving=20 >> them to be used at some indeterminate later time. And users don't = "learn=20 >> to recognize" that a loop doesn't hide all variables from the parent=20= >> scope; it would be very peculiar if it did. >=20 > 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. =20 Working in Go now for several years I'd say one of its biggest foot guns = that I consistently run into when doing code reviews and even in my own = code is block-level scoping where one variable shadows the same named = variable outside the block and the inner variable is updated when the = intention was to update the outer variable. In short, block level scoping is a convenience that does more harm than = good. At least in my experience. Thus I would highly recommend *not* adding block level variable scope to = PHP where a block in the middle of a function shadows a variable outside = the block, and that variable is used below the block, such as for a = return value. =20 #jmtcw #fwiw -Mike=