Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129630 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 F22FC1A00BC for ; Tue, 16 Dec 2025 22:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765924277; bh=M8ny2FYSEswfKtVQwIPiTRlqk7yspUQmaYBwN2aZoWU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=My/MpxUAiqXkg/vXNOTObhd5gco5D0IG7wsot+DEF5xEFO+FLmgE82Z6svAFlWxm4 HSVxpJB6i+MUSbwe4/kpzSTKKBRcxVjFghL1r4smetUZYi9VHLmUfP2yhhfELkxfCx 0mTv9jo3t3SXnKN8ieQV6VTOV1Mu9lvD+jceM+1iKTA7v724S3QbKy21eDOGjXUyUc JJJLFptqz4I16bYveDDPhZ4qKayMN2GLpf7E4th6qQM90SHt8jCkNDear5QM9X1Yrl 7KRRYLtry6ta42E1fQ62G0Qiuet//dMqvhBX8lz/8MohM/We5Ugtn/q8X2qwqcQhcq SGoqidSWo4M+g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 96E4E1805B4 for ; Tue, 16 Dec 2025 22:31:13 +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 fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (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, 16 Dec 2025 22:31:13 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 04F98140021E for ; Tue, 16 Dec 2025 17:31:08 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 16 Dec 2025 17:31:08 -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=1765924268; x=1766010668; bh=8ZNgmmecA/ycKptpVq2y9ZDfZeiTBkS0cgItE/bhFaM=; b= WxLF8x0ZgdWl0fQKueXtmvi/bjFJe2RfJNonLwAAKPNpr4baHgla1mvXjypBi2jj /+ksJ7T5CVYkTyFGXqseMtjIf2gLuM5sMcBfMrZDIt8aoN/4V33mSHqcTkQVjb0j NgMnUt/8AIHZCzQ2t9HnNWeQMPJMAuy8lWPGhGhcw6Qn+hfS57ebXDLrNZcCOPAt hYH06rZMyxh3qmg44G5bxQXnlP+x+6OuIgDvNwLHnEvqWAvvcuwHkFXbAxzmSIDa 4EQeWX69czhjFpC5Nox3KEezRk9tvQkzMPfdxo6Y/kB0b+X2rP3TL/grAUNElkSO cvx+YVcdo5ty3gnukpAcbg== 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=1765924268; x=1766010668; bh=8 ZNgmmecA/ycKptpVq2y9ZDfZeiTBkS0cgItE/bhFaM=; b=dU7F7ozbDu0kTYRe2 YCryI6HPFCKVnVkXmG88VIeqNB3fnT3Aw/oOAEUa5ooqDnDsYdL1FOx8170Lqzqp +EayvCL4JqQNlxOijOzIDpdp8U/VJlnNzhHA5Nopti/LrlqB2476w7UsYGC++4P2 3JoA3bxGockobz5G4HekwNDHFUDghAbcVVHjAYoqF0y2Z+GjavWW3EYajthpGcmj mr/QfSvRD15tkPDPsermAv0A0B2VFxWmB6nXOtPIS6/QRXll8A4q/AfyH1TiMLp/ WQQ7zjLoliswAkq8xbhOwp6D7XvkkAszgARRLeE1YbsGOS8CrAGklXghFFJDjTCU f34xg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdegtdeklecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttd dvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehi mhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhepffekve duffduvdehjedvfeekleeftddugeefheejudehgeeiudffgeeggeevfeehnecuvehluhhs thgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhhph esrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 16 Dec 2025 17:31:07 -0500 (EST) Message-ID: <0f9933bd-c836-430e-b345-3a4865313272@rwec.co.uk> Date: Tue, 16 Dec 2025 22:31:06 +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] Context Managers To: internals@lists.php.net References: <70A79513-5503-467E-BC6F-2B0494A3EBB9@benramsey.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 16/12/2025 21:40, Matthew Weier O'Phinney wrote: > I want block scoping; I have been bitten by accidental > re-assignment within a block many times, and hate having to come up > with an ever-so-slightly-different variable name to disambiguate. I > don't care if it's this proposal or the "let" proposal in terms of how > the engine handles it - but the syntax of "using (expression => $var)" > isn't going to get my vote due to how easily it can be written > incorrectly. I want block scoping too. I don't think *either* of the current proposals achieves that elegantly. Context Managers aren't even trying to achieve it. Block scoping of the context variable is a minor design detail which was added after the RFC was shared with the list. You could in theory write a Context Manager which took a value in its constructor and spat it out unchanged from its "enter" method, but it would be a weird and wasteful way to create a local variable. The let() block proposal *is* about block scoping, but only for its own special kind of block. I am not convinced by the reasons given for using this unusual approach. I would much rather we copy the precedent established by ALGOL 60 years ago, and have variable declarations as statements which can appear in the body of any block. In particular, I would probably just copy JavaScript: allow "let $foo;" and "let $foo=expression;" anywhere, and disallow use in the "temporal dead zone" between the start of the block and the declaration. However, I would also like Context Managers; which are a separate feature, giving nice sugar for re-usable try-finally blocks. -- Rowan Tommins [IMSoP]