Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129758 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 6EE3D1A00BC for ; Thu, 15 Jan 2026 09:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1768467824; bh=vcVgvnJrDQI8N4wiwEmHg/XdOXN5FfPJR13cra832lY=; h=Date:From:To:Subject:In-Reply-To:References:From; b=QxIaxCFljjWu6yBjxx8KFOXL2LplhSprdChIHMjQQ5REAGMWEpLJj/z4Wvd8mZpGD vR+KRMa02/L/iV2YFK3XT8y8MyPRAMEFp0acGW7G7Xt9qaKIzWpF/YhO1bjh+QOFc0 g+useNm5nxl/jM84HesiCp9/hRURLhNFJ/L1Q5zrN5bg+rihVyJLx1qyY3MOLTCyJX Tj9LjPn6e7YVn1dAyKQTipvSB4EPpz4GXDvosAM53QPXCqZJNSWvH3hX3nJQCmzow5 JD4tEvywoOwZq3TpxaXxsvVkwptzap2kLjuC6jrBD3KafVYteJmuqN623UI7R1lmaf 8SVblutpWC8YA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EB9AB180056 for ; Thu, 15 Jan 2026 09:03:43 +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, SPF_PASS 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 ; Thu, 15 Jan 2026 09:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1768467816; bh=aMOZNqNX3cvShG5OgBObCD/kZbNbx32MOWbyfq8FcsA=; h=MIME-Version:Date:From:To:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=oLKiFsxIAkQOBSHehInfxAibnYbsBD7BdawD2DBEZiyP7dirAf1kJbjWPjeWz6DOd RM/yRHfGGoRyIFTRdTrO+LSqX6BklzY6028Bb4zrCqZVK2HvWfo7mmJuP4XLsq41Te +cJPbqIGGseyA2PMILJpwB6h8vTRgpZK7wTc8RYcVsSjBRusD0X5agMKvO+fiU1vR0 MR7P8Qc0GuKffVGQf4+9cyAJjB4/XhJAysUJko2EBTOzTsTy8VHWO/ReBJA8Zm1gqH mv9QGQG4UPpjcACT4HLMFyesyRftOJu5vMnypQgaZapebqhU5N+AlvNFGcIAGisGyT /9Mng1BnvDTIg== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 15 Jan 2026 10:03:36 +0100 To: "Rowan Tommins [IMSoP]" , internals@lists.php.net Subject: Re: [PHP-DEV] Examples comparing Block Scoped RAII and Context Managers In-Reply-To: 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> Message-ID: <437656ab-8113-43de-b68d-11d2083320d0@bastelstu.be> 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 On 12/18/25 10:16, Rowan Tommins [IMSoP] wrote: > 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. That is true from a purely technical perspective, since syntax is independent from semantics. But the choice of syntax influences users' expectations with regard to semantics and as I've outlined, we believe that the semantics we've chosen fits PHP best and that the syntax we've chosen hints at the semantics best. >> 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. Part of it probably is probably a subconscious feeling, but I'll try with an explanation that you may or may not be able to agree with. Existing constructs in PHP that take a list of multiple “items” behave equivalent to consecutive single-item entries. Or in less abstract terms: const FOO = 1, BAR = 2; is equivalent to: const FOO = 1; const BAR = 2; So to me it is only natural to extend that logic to the `let()` construct, which only leaves the let($a) let ($b) desugaring which then implies (3). In fact, the following works: const FOO = 1, BAR = FOO + 1; var_dump(FOO, BAR); and defines `BAR = 2` and const FOO = BAR + 1, BAR = 1; throws, because `BAR` is undefined when defining `FOO`. This is exactly matching the proposed semantics of `let()`. > 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. Yes, but the “more traditional syntax” would also leave the possibility of (1) or (2) - unless restricted to the start of the block as in C90. However it would compose less well with the existing control structures, e.g. by requiring the dedicated syntax for declarations that should live for a single `if()` construct. > The only thing that using commas automatically does is forbids jump > targets (goto labels or switch cases) in between the declarations. It also forbids nested blocks and any other “arbitrarily complex code” in-between declarations. Yes, I understand that folks can use arbitrary expressions on the right side of the declaration (including assignments), but that is more unlikely compared to a more “free-form” syntax that allows arbitrary statements, including arbitrary control flow. I also believe that the explicit separation of declaration and usage provides for a nice visual barrier of "before declaration, definitely old variable", "after declaration, definitely new variable" and "declaration phase, a small chance of ambiguity when declaring a variable that is used in the declaration of an earlier one". Best regards Tim Düsterhus