Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129075 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 EE7CC1A00BC for ; Tue, 4 Nov 2025 18:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762280388; bh=2z1ALBZNAgODIS/SSRDgr9IOfZZdrca88OsvjuVAeaE=; h=Date:From:To:Subject:In-Reply-To:References:From; b=X97Be1l/oX3zY/2437rtjewFNPtxd4k6PGEjKKDuCJRo6cFaSS5gcgWzhXXdMkQVj xBw+1Ko2gDsIvH/jnHxwBZ/OVeZ66S7TtCgWf+lxj3tkRkZ27z028ouf1n80q7/Lkw aQTRNgmS5he5+zX4DksQqTtfqpvet72Y3OtDi7kefzB/+r2CjOoCdsba9Bo+eeC1Z5 rn9VnljA4ocS2YvLrDG0ks4G6sDDpne+0RtQI7IyCpINRQV5h5CBlT1+xp78+RSg5D 1Aux6J4EhNjqT/pCYf0QFYu24QcMhzb2ZRa+TIT5HMQbo2SiJREf/7WCGsNQky8HES T/JJXNr2aMDFw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A277518037E for ; Tue, 4 Nov 2025 18:19: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 fout-a7-smtp.messagingengine.com (fout-a7-smtp.messagingengine.com [103.168.172.150]) (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, 4 Nov 2025 18:19:47 +0000 (UTC) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id A5A0CEC0527 for ; Tue, 4 Nov 2025 13:19:41 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Tue, 04 Nov 2025 13:19: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=1762280381; x=1762366781; bh=OUPHKSFXIu8upyrnZOVTo59AWEvEASpbW1bV9Ux26hc=; b= OnP8xtPW0KS5LsIDb5szLoojTy8nHp5pcFJqlaxA3beeaUmZmQMNHCt+RKlSwQKh 1vvfuQ4YuJ3f6kU8CSckqF5ULd5Ih9sL2RDz2t6rCmoKEnN/+Vic1bNi+Bpaw6+l 3O3kAMjqX9v+6t1Q9+o0jzypl5q1aE21aQt0K1slONAqOVeEuwTGqvhOImxDR4QE VE7PyXZut8ItnGpEBRykJ2LdrCPpqh5JP7ldTZDKFl3L/I+TOdb6ramnglPFkaYo E6k/mQN7AXbYitspmVLIWodBPEpLdG7mBKYdIKdXepBVi6vHSq4ZBCTGvpYawjr0 zHfOGOc0K7XOZiQ6rBfGsA== 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=1762280381; x=1762366781; bh=O UPHKSFXIu8upyrnZOVTo59AWEvEASpbW1bV9Ux26hc=; b=cc33HjBfBjeyuNvBj opNH/D7EAHlMihOAz+oG4GbzcJZYEH8naxNr/m2HvC3KSHy0z/re6tvWg/IwQqcp KArF+sGVPTwWWe4CN9GIwgdSSAl2Af8w4sI2lt7yWMg37vMdZM56zoVCn3swhYPN vZ+dHYgPb3PSA6tKCEuZWLEFPnVstYT8URNcr/7VpxZe3gYWoHMA49EmE9MLcDOM sRHkktWE1W2aUQlnwivzvWqe3eGXg6D5+DCJFaMfvAxEdxLkuN0iUsxAtpibZCye Tq2KqbwiQWJlbfO7t4Ebsj9jwdbhuGW/zCfXOjUJsbB/x5zQ9D9vAhvtwQl0eWht wZORQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddukedujedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpeffhffvufgfjghfkfggtgfgsehtqhhmtd dtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceo ihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeffte dvkeekledvueeivdfgtddtfeekiefghfegueeigfffffeiudduteevueejteenucffohhm rghinhepphihthhhohhnrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrg hmpehmrghilhhfrhhomhepihhmshhophdrphhhphesrhifvggtrdgtohdruhhkpdhnsggp rhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnh grlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 4 Nov 2025 13:19:40 -0500 (EST) Date: Tue, 04 Nov 2025 18:19:39 +0000 To: internals@lists.php.net Subject: Re: [PHP-DEV] [RFC][Discussion] use construct (Block Scoping) User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <1F3473C7-5D83-48D3-964E-A63D6F44D21E@rwec.co.uk> Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 3 November 2025 21:46:15 GMT, Seifeddine Gmati wrote: >Hello internals, > >Tim and I would like to open the discussion on our new RFC that we've bee= n >working on: "use construct (Block Scoping)"=2E Hi both,=20 I agree with Ed and with Arnaud: this feels like it's trying to squeeze tw= o different features into one syntax and ends up with an awkward version of= both=2E=20 For what Python calls "context managers", it offers very little: the progr= ammer is still reliant on reference counting and cycle collection to actual= ly clean up the resource, and objects can't directly interact with the cont= ext life cycle=2E Python in particular has a very carefully designed solution, and the PEP i= s well worth reading: I think most = of that could be directly ported to PHP=2E For block scoping of "normal" variables it feels clunky to add an extra bl= ock, rather than declaring the variable with a keyword like "let" or "var"= =2E 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 writ= e the equivalent of this: foreach ($array as let &$value) { I have said before that an opt-in block scope would solve my main concern = about automatically capturing variables in closures, because you could writ= e this to make scope explicit:=20 $foo =3D fn() { let $localVar; something($localVar, $capturedVar); something_else(); } With this proposal, that would again be rather verbose: a mandatory extra = set of braces, to put the scope inside the closure:=20 $foo =3D fn() { let($localVar) { something($localVar, $capturedVar); something_else(); } } I think splitting the two use cases (context managers and scoped variables= ) would allow us to have much better solutions for both=2E Rowan Tommins [IMSoP]