Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129203 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 A6E431A00BC for ; Tue, 11 Nov 2025 22:43:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762901028; bh=umDlyU2ewwlcu7bPjlkZh996U5ZltAfXqVkO1BZjBuo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Ax+N01S04cVYiRYEK6dpBzT7RetulOWjBWgOkR0DKg1XnSfiLW3vjzqdwk05F9q91 d2cxoJx5sW9J8H4FHJd6F50wmYjH/aY0h4TR77xLs6CpQlqqA8kqnTvQITobQe+DOZ uq2ayhWNv9OBLXR5NGTrsWM8NLXeZB4QuYhiyLajLeh6ss0ETPo6AW62MVCbvV45pi DJU+oB2iyJyjueRw/bKXoQNYreG7RmbonKGYRGKf3PLu2/lAKrGtqSeZUKiUJSXG63 1PqfNHqXtVaUYdAihy1azHrHjwD5WHzhObyr6i0dM0Y3jUEc1nhvUpMuFxAwe7/T7A jvpBE474TN6YQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 40640180081 for ; Tue, 11 Nov 2025 22:43:47 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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 ; Tue, 11 Nov 2025 22:43:46 +0000 (UTC) Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 0C3C77A0030 for ; Tue, 11 Nov 2025 17:43:41 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Tue, 11 Nov 2025 17:43:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1762901020; x=1762987420; bh=PAope7xKXeYd75tMP5GGtpmY3BLLqwtaFiYsBNub9hs=; b= g2IwwVqwitRw3mOiIumaHCFcbyl3XOLDVBUG3CEtu+OUf2Hw5VDE+Xg4v3ZUZwUE x/3KVBZMZqnP2/AmOw7eKP9V/XxM/zG7KAiN8AoAkWkF/TF5+6hKaHcgSH87iYbS Iuop6c7P1FQXfs5GNDMbGfMSfJt5m3dQSCHNZOxDaC+pnoPcAOwQ+HtIjtfqnZYZ RxQ82IFfn4Dg9reaJyRlTUMj1uNdwO96TcvrT2fkVY9NU6r8Yc9QEydS+ZaClxxn LHKqhQEkgfyjP/CSGr6IeOZFWYJhNeSnE5tRNv6Q4QL0of5d34LYVCMLS2IBsi9D pcQMP2nCqbox9wJLLvqeUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1762901020; x=1762987420; bh=P Aope7xKXeYd75tMP5GGtpmY3BLLqwtaFiYsBNub9hs=; b=P5F2QprbIg2Dt4UvG Rygtd+bwdcq34nApkGJ2k8mmsCi5rSAQQN6a/QM1hSIctg5QJUKCcpoYHFGdpouI jcchhoG7all3xxM9kxYrk9k0HZ0BSXVKTOUxNIxKx5wZ1CBNPSqjjpzr8+/zxV/z J97OsIAzjWJJ0j9zwRjXwd+JBJlW5dCn44dzO0WrCVZX3KmIo1UI4RV+mUYZeG6j 8AcuU5J6QbqqKRWgZvXvD05AVxE78rutUMw6tC8mIE/Mou+sRNqrOlN+eWhaKKVN tUcfXQlvm1wRwq5tWbl1+Pw6MmOEascnczrcLGAuAWoAQVWe7OwBy7F0XERVHDxQ 4IIfw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvtddvgedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucgoufhushhpvggtthffohhmrghinhculdegledmnecujf gurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomhepfdftohifrghn ucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtg hordhukheqnecuggftrfgrthhtvghrnhepjeeggfehjeevkeelhfdugfffteevgeejheet gfetueeiheegvedtheelhffhueeunecuffhomhgrihhnpeefvheglhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhp hhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtph houhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 11 Nov 2025 17:43:40 -0500 (EST) Message-ID: <84b9dc16-3eb3-4283-b015-3af29fc0e55d@rwec.co.uk> Date: Tue, 11 Nov 2025 22:43:39 +0000 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) To: internals@lists.php.net References: <1F3473C7-5D83-48D3-964E-A63D6F44D21E@rwec.co.uk> <4998b4c6-0474-4f0c-b63a-9909b8acfa96@bastelstu.be> <018421f64342a0d960589b4c8eea5cc5@bastelstu.be> Content-Language: en-GB In-Reply-To: <018421f64342a0d960589b4c8eea5cc5@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 11/11/2025 21:12, Tim Düsterhus wrote: > That's fair. I'll look into adding more explicit comparisons to the > RFC together with Seifeddine. My short answer here would be that > JavaScript already had explicit scoping by means of `var` and thus > folks are already used to needing to declare variables. Moving to > `let` is just a smaller incremental change. This is different from PHP > where all variables exist implicitly, which also means that semantics > from other languages need to be adapted. Technically, JavaScript variables don't have to be declared either; the difference is that they are global by default, and since function-scope is generally more useful, people are indeed very familiar with "var". PHP does have optional keywords that declare a variable with specific scope, just much less frequently used: "global" and "static". Regarding the discussion on shadowing vs hoisting: - Both "global" and "static" can shadow local variables, and indeed each other: https://3v4l.org/vPr2A - Since the shadowing lasts until the end of the function, a shadowed local variable is never re-instated, and will be de-allocated if it was the only reference: https://3v4l.org/VBVkX - Somewhat unusually, they do this as run-time statements, so you can *conditionally* shadow variables: https://3v4l.org/fK9VJ Whether these are *good* semantics to copy for a block-scoped variable, I'm not sure; but they are existing PHP semantics for a very similar situation. >>  I'm not aware of any language that requires a specific kind of block >> in order to introduce a new scope, but that doesn't mean it's a bad >> idea. The approaches I am aware of are: > > The closest comparison to “specific kind of block” might perhaps be > older versions of C which require all variables to be declared - and > for them to be declared at the top of the scope without any logic > running in-between. The big difference is the need for an extra level of indent (or, at least, an extra pair of braces, which most people will probably assume needs an extra level of indent). More often than not, there is an existing block you want to scope to - a particular loop, or a conditional branch, etc. I do see the advantage of forcing them to the start, though. Languages in the Pascal family might be another comparison to explore - variables are all declared in a separate block at the top of a function. Off-hand, I'm not sure if any allow an arbitrary nested block just to introduce additional variables. Regards, -- Rowan Tommins [IMSoP]