Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129169 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 138BE1A00BC for ; Sun, 9 Nov 2025 16:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762707133; bh=EjzqFBaabDWIxSNGJZKxaTyDSRdH+qNpvTAXpKOaTGc=; h=Date:From:Subject:To:References:In-Reply-To:From; b=hLz8rtRBBFxQ2/Hk9WJVBoO09tl5H4zWkfq0oiUDFLI63Mf0FapjFmaYTjipoc3r+ AWx469L1FSqrrQ2b8NcWZUPa6wW/u/GN3UnjM6RZUv/5H5JSHl3WVkqr+2YVJOOyC/ o6Ijb1p5IhVj5EH0sYbYwlr574nIUURZgvutDWztgu73qN0ZzxDqJ8k3zRRSlJ6weB Om85Ams21u9Gjx6B/CEJXM75nq+92hNajQYKv8BNeZfjIfasPvAiyOTENscKwXyhRO 5X3fdF0Lzku9Y6VVWquVMik8GjAVh2hOd84CdfokH26GTosRiK2e1cIHVt5HJbGJsg S42kjKZd4/Cyw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7F685180041 for ; Sun, 9 Nov 2025 16:52:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 9 Nov 2025 16:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1762707122; bh=fDeDQHEbPFL1xqzSjszxF5BGP/X22+mLaZ04fqcVr2M=; h=Message-ID:Date:MIME-Version:From:Subject:To:References: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=Wg1jX2UMCyqCEYaIoyx1yjt23USTNCG1m1WC1fiKLb5qE+0sK+ZLAGQQcLjDFWE/e 9nQzGMCApkSyGGXHB+Ck1HKIDzjRBNd3TYeQ1kGHK708mieqtZIoHK8yvTzztXxpOe N72ziKlxipGAE7H7N/WpL2GxgYV+2SL4rJc5C/CDS39Yy3fJgDQ7ryiUw4rzvN8qTL L3a7RTF9GcYGMJ4ECUO0AVwntFGT58MmGAOtEeJxMRPDNPBa+k7P5Os02Q3NRiZY85 D6WrY+qGhTPx3MJpygKbhNdRVFH5iGbhTuw1FNwHOsxd/OZIiom1XBWVwRCcS8jeWh kti+Hhq6BArCg== Message-ID: <4998b4c6-0474-4f0c-b63a-9909b8acfa96@bastelstu.be> Date: Sun, 9 Nov 2025 17:52:01 +0100 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) To: "Rowan Tommins [IMSoP]" , internals@lists.php.net References: <1F3473C7-5D83-48D3-964E-A63D6F44D21E@rwec.co.uk> Content-Language: en-US In-Reply-To: <1F3473C7-5D83-48D3-964E-A63D6F44D21E@rwec.co.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Apologies for the late response. An unexpected high priority task came up at work on Thursday and I wanted to make sure to provide a proper reply. On 11/4/25 19:19, Rowan Tommins [IMSoP] wrote: > I agree with Ed and with Arnaud: this feels like it's trying to squeeze two different features into one syntax and ends up with an awkward version of both. We don't think so. Our goal with this proposal is - as the title of the RFC suggests - making block scoping / limiting lifetimes of variables more convenient to use. The goal is to make it easier for developers and static analysis tools to reason about the code, for example because variables are less likely to implicitly change their type. For this reason the RFC very intentionally relies on the existing semantics of PHP and leaves anything more complicated to future scope, as Seifeddine also mentioned in response to Edmond. > For block scoping of "normal" variables it feels clunky to add an extra block, rather than declaring the variable with a keyword like "let" or "var". This is particularly obvious in the foreach example, where the variable has to be named twice on one line: > > use ($value) foreach ($array as &$value) { > > Languages with a keyword for declaring variable scope instead let you write the equivalent of this: > > foreach ($array as let &$value) { Requiring to declare all block scoped variables at the start of the block is an intentional decision to keep the scope easy to reason about. Consider this example: function foo() { $a = 1; var_dump($a); { var_dump($a); let $a = 2; var_dump($a); } var_dump($a); } What would you expect the output of each of the `var_dump()`s to be? With regard to the foreach, I agree there is no ambiguity. I can imagine a follow-up that desugars: foreach ($array as let &$value); to use ($value) foreach ($array as &$value); Or if you feel that this is important to have right away, I can look into how complicated the implementation would be? > I think splitting the two use cases (context managers and scoped variables) would allow us to have much better solutions for both. As mentioned above, this RFC explicitly is not a context manager proposal. It's scoping - but it would make the existing lifetime semantics easier accessible for what you call context managers. Given the opinions disliking overloading the `use()` keyword, I have discussed the keyword choice with Seifeddine. Personally I prefer `let()` over all alternatives for this reason. Best regards Tim Düsterhus