Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129649 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 91A171A00BC for ; Thu, 18 Dec 2025 09:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1766049401; bh=U+LrP2ffeEJI/wymLATLtu2tTEUCW/Xsd3qVxiDp0xg=; h=Date:Subject:To:References:From:In-Reply-To:From; b=AtGnobLS3hjCtjeMnJgt5jOOnrQQISCSzsx3we40OZ0tKbCOLWBk6BYVohEIYvipv qqXLa9iu2UIzLHzb9oPkDjUm+CuiikcYliz60SbVt6skAQmOU3YBYAZj7d3BeoeDVC mIga0rTaBjJYRCEdzpSFmyJSIb9GBHsAO7uJYXsT7hEmJoyB2qsiZ8Ziwvuy6Rbbju ZOZRl//qMTk2ZCcjhJMVJyBqYzpVIKmtdLzM6XjU9r1a4rmpqehVX+Xi6QIPidhWVt y96v5pTOaj4OVPArVOEWDYk43d9mxWDwE1VMR90leY+/pzUqQO4Bdfm3tDdysk+U+o /ZTfUUrZ2z8WQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1425C180055 for ; Thu, 18 Dec 2025 09:16:40 +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.1 required=5.0 tests=BAYES_50,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 fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 ; Thu, 18 Dec 2025 09:16:39 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.phl.internal (Postfix) with ESMTP id 4CE82EC01A7 for ; Thu, 18 Dec 2025 04:16:34 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 18 Dec 2025 04:16:34 -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=fm1; t=1766049394; x=1766135794; bh=np4x35rhUOdQgJGa1RWbCujH3Cqn+RAsUtLOY79PI6s=; b= U8kdnwH/1kx+UjeQt+NndIiLddZmPNmApth9hUgVmwlf6RY+2FmAddjiKo/57lA2 H6PdejSzjSxt70+HeWCDbNju2CtpCH/UbNXtHi4Nt7pdDzBiw74ecs8FHIpBxnDU J5QQqNqVuTGNxOa7+uWwM+T41f1mqqpVC6J2R4fY4kI/a4YTdkOgB6mtEMEF4LCM WsOP1fAIPo+3I/D+bO10HTWzUSMPAYQSV5Nc1PKDI0iEQ8xxvFEVWRLASdQIhCBc TfY88/Mppwqtdif/Qguh0ejgyMNYepoa/62+m7cEeJsF13LAD/UHxgyWDKDbwiX5 ojrRu1R3JSNqYRg1m4kivg== 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=fm1; t=1766049394; x=1766135794; bh=n p4x35rhUOdQgJGa1RWbCujH3Cqn+RAsUtLOY79PI6s=; b=MmAo3vlRyFIP80ttA K1R7LIzJDXChOUANfkpA9tJ+fzCkKeb4ORfOvkjFvx6SMPGskHME95Z7/Aa7n+0O whoVS40LLtMHHVIgp/1P8TDq3Un25laIDcWrl+JRUx9OGcZQBueq9cT6XdT53nOX uK5w87j5vga9/2/EGte2K0WWYh9+SXAxF9BNxcDdeFeDZ0+02aREc51EftX6fKHD IwcZXS/BMPOkYRrohyKD4/PiTG+IbohN4+dOHSCA6yX4rDubLO15ewg8v9bRaFla 4atU1Iad92DxS5ZCwDzvZfpQg4NkfxYjG44SyAZZ1lO4aYbj3Dl8s7axf3wkV+SI 247AQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdeghedtgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttd dvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehi mhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepgedtvd eivdekheehleduueffkeekuedtueduheelgeeiteffhfeuuedtkedvueevnecuffhomhgr ihhnpegvgihtvghrnhgrlhhsrdhiohenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgs pghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrh hnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 18 Dec 2025 04:16:33 -0500 (EST) Message-ID: Date: Thu, 18 Dec 2025 09:16:31 +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] Examples comparing Block Scoped RAII and Context Managers To: internals@lists.php.net References: <26a2f13c-f318-4d6c-9595-bfaaebcbabcb@rwec.co.uk> <78bfa50ad7c5111a1c6caaff3a525255@bastelstu.be> <52165B35-D495-40C8-97B3-9684ED30F220@rwec.co.uk> <954a2c05-af46-4df0-bc42-fc14a80dae51@bastelstu.be> Content-Language: en-GB In-Reply-To: <954a2c05-af46-4df0-bc42-fc14a80dae51@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 18/12/2025 00:17, Tim Düsterhus wrote: > Yes. > >     let ($foo, $bar) { … } > > is equivalent to > >     let ($foo) { >         let($bar) { … } >     } Yeah, I guess I didn't realise the implications of that equivalence. From the syntax alone, I vaguely assumed that the two declarations happened "simultaneously", and didn't think very hard what that meant. >> If you can do that, presumably you can do this: >> >> let( >>       $foo = bar($baz), // What is $baz referring to? Particularly if >> it is a by-reference out parameter. >>       $baz = 1, >>   ) >> >> Which is a direct translation of an example you gave here: >> > > The `$baz` in `bar($baz)` is referring to whatever value `$baz` has at > that point in time. As written, that sentence doesn't really say anything; but from the context of the discussion, I get what you're trying to say. The point though is that any answer you give is just a design decision you've made; and the exact same decision could be made with more traditional syntax, and apply to the original example. > 1. The “temporal dead zone” is not something that can exist. > 2. And users do not need to wonder if declarations are hoisted. This is just plain false. The exact same ambiguity exists, you have just chosen how to resolve it. > For the example in the email you linked, I am including it here once > more (with an additional $baz = 2 assignment at the start): > >     $baz = 2; >     { >          let $foo = bar($baz); > >          let $baz = 1; >      } > > 1. If there is a temporal dead zone, the call `bar($baz)` is invalid > (throws an Error). > 2. If declarations are hoisted, the call to `bar($baz)` could be (1) > an access to an undefined variable (if it behaves as if there was an > `unset($baz)`, which would be behavior that is technically different > from the TDZ). It could also be a valid access to a variable > containing `null` (if all variables are initialized to `null`). > *Theoretically* it could also be `1`, if only constant expressions are > legal and the initializer is also hoisted. > 3. If the lifetime of the block-scoped `$baz` only starts at the point > of declaration - effectively an invisible nested block - it behaves as > if it was `bar(2)`, since the current value of `$baz` is `2`. Agreed. It's probably worth calling out that (1) is effectively a subset of (2) designed to avoid the confusion that full hoisting causes. There's also a variant of (3) where variable shadowing is forbidden, so the "let $baz = 1" would throw an Error. And all of those options are available to a comma-separated version as well. > To me the syntax of the `let()` construct very strongly suggests (3) I don't really see why. As I said above, the comma-separated list made me think of "simultaneous" action, which I think would imply (1), because accessing a variable "while it's being declared" would make no sense. Option 3 is not necessarily a "wrong" choice, but it's a choice you have made, and you could equally use more traditional syntax and make that same choice. > This is what I meant by “there is a less rigid relationship between > the individual statements” in the previous email. Note that it also > said “Forcing all the declarations into a single statement would > resolve that > ambiguity […]”, since that would be isomorphic to the `let()` > construct if the declaration is forced to be at the top of the block. I don't think separating the declarations with "," vs ";" makes any difference. The only way to fully avoid the ambiguity is to limit the initialisers to constant expressions. As soon as you allow "let $foo = $bar" and "let $bar", with whatever punctuation you choose, there is a chance for ambiguity about how to resolve "$bar". The only thing that using commas automatically does is forbids jump targets (goto labels or switch cases) in between the declarations. On 18/12/2025 00:21, Tim Düsterhus wrote: > > And with that I'm *really* going to be off for vacation. Have a great break :) -- Rowan Tommins [IMSoP]