Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117913 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12961 invoked from network); 12 Jun 2022 11:12:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2022 11:12:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 33D3A1804D4 for ; Sun, 12 Jun 2022 05:59:08 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, 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-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 05:59:07 -0700 (PDT) Received: by mail-wr1-f46.google.com with SMTP id v14so4077376wra.5 for ; Sun, 12 Jun 2022 05:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=MPHUZDZ6nboLgk3ORjxO3cfsDVhIRdt6Lbg4ua74F+g=; b=pID/vL9QNmLa6fsQy4lE8bFYQpgAMy3nbDtljFoCcYH9L8wreNQ04YFd57Na951PDM bhb4ctVQXI8PybQQ9UwIMbxcga7n3cYMCb+LOS7VOLxYfgxTpVu4bVLBUKiPtjY2VlDU xXTdKPtcL1nG0jA/ABbsEGhB7cndqecQm2FTX0ZoAZZLuMhNXuJIswSFqac9k1yU0SxY cbUOjBTinCT3f2e4N0xvNQBqcwJRCemZ2DPvzB6B10BfGV0Ye7H9KRRFRPoVsqSy9ETa hwSAhOByZkAO2ewhwO5/ZRAS/EaS+6cjkWegFkdM6lFKBZSX8np5bCdBty3R0lCr7pJS PS3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=MPHUZDZ6nboLgk3ORjxO3cfsDVhIRdt6Lbg4ua74F+g=; b=Oi9zvtyhYtyoVpbXuaJm8aqVlmKPA4F/FLoXrlCCqzF1U7LL9Ol1XDhusOK6I0KeFW 1AtuA+wjwhMOXHlXKF5pqLcXbPp4qENM5OI85k2JgBhaE3rTmG/yj0bi1c1csYdftZqy qv6lEGsjdikGVgztjhnCsv6SCxZn71mTRxgb8Z76RYigXLYalewBLDFzOrndgx8fho7S Du+JCD1y1XeRBGvcXabIFHERHHUemwSLA0bMlyZqyOSFhAKi0mDOLTPzFpa89ZGCVA9b c2D2lxpXg5/M3Pt3yHcSAa0QkPKv/epsaWjSr1EuV/ppGT86RYoUoiLRFsdCVxP8kP/G /wxA== X-Gm-Message-State: AOAM531veAbaB8UKc6JfyBZ9bbT8e7o+v9z3Pm0BwiX10MxAh6eDfS/E fyH6ihXwrvloq6HLyzV4b4MSbP4P/kg= X-Google-Smtp-Source: ABdhPJw343H2vQM6R/Hpu0FsHIgK0ZV7zSLpdkmgYk6NQCAhyzl9jhsndIHjQheqWXYl85BP2LlSyw== X-Received: by 2002:a5d:4e49:0:b0:213:baef:4788 with SMTP id r9-20020a5d4e49000000b00213baef4788mr49208152wrt.68.1655038746583; Sun, 12 Jun 2022 05:59:06 -0700 (PDT) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id q7-20020a056000136700b0020c6b78eb5asm5476309wrz.68.2022.06.12.05.58.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Jun 2022 05:58:56 -0700 (PDT) Message-ID: <6b563cc9-8f2f-6577-fe1a-b945fc67054e@gmail.com> Date: Sun, 12 Jun 2022 13:58:43 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Content-Language: en-GB To: internals@lists.php.net References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <8310f3fd-0011-970e-5379-b2b6e03942b2@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: rowan.collins@gmail.com (Rowan Tommins) On 12/06/2022 03:01, Larry Garfield wrote: >> ... 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. That's not what the RFC example implies, though; it implies that someone might expect $guests and $guestsIds to not be usable *inside* the foreach loop, because they were declared *outside* it. I don't know of any language where entering a loop creates a completely empty symbol table, do you? Whether or not $guest, having been declared *inside* the loop, is visible *after* the loop is a completely different question, and one that doesn't apply to closures - the content of the closure hasn't been executed yet, so it is inevitably a black box to the code after it. > PHP is fairly internally consistent: functions and classes create a scope, nothing else does. This RFC doesn't change that one way or another... The RFC fundamentally changes the rule that a function always creates a new, *empty* scope. Every variable that is not local to that scope has to be explicitly imported, one way or another. Every language I know where scopes do *not* start out empty has keywords for marking which variables are definitely local to that block. That's why I think a "var" or "let" equivalent is a natural accompaniment to changing PHP's rules in this way. > 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. It's a cute idea, but I don't think "if you miss most of the letters out of a word, it means this special thing" is at all memorable. I've never heard the syntax added in 7.4 called "fn functions", but I've frequently heard it called "arrow functions", because what stands out to people is the "=>". The keyword is only there because ($a)=>$b on its own would collide with array syntax. I would much rather see "fn" and "function" become synonyms, so that "public fn foo() {}" is a valid method declaration, and "function() => $foo" is a valid arrow function. Regards, -- Rowan Tommins [IMSoP]