Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130790 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 4B5ED1A00BC for ; Thu, 7 May 2026 10:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1778151171; bh=gI8vlOVOeQ7IdXJeJSM7hu+gegVQqRRAk7UtQSbvtx0=; h=Date:From:To:Subject:In-Reply-To:References:From; b=Z5lwONmT1wE8rCgzQ4utbvJxRVkjpmQorqilRekdEYnOmr42BH0ZkvA3zHY5j3jPV fzDr5w6DQsyA6pywFpAHqvWIAshGwbUaFPF0pU6w7DQ+03oBbnoRkHs8KMsBDeNSyt HDfN6QhFoGuLmofyXm+6+jMXV7YHYlCVOd8/2Ycav7m/WM+YzTwFO/xCry9ZEU97Hy PAWUOWlRTTjYdUG3EmINWc0DBN+RI7LkbOAJXgwWR3RKj4wPZzHd5j2m7cEN3othEr vEkJh6nxG5YlqZTXW0nJIvrz9VeloGxpIgmPQxRh3jIuHxgyWp2RZ1kg265KJUrGWD x26j/D6brkjtg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1D497180086 for ; Thu, 7 May 2026 10:52:51 +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-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (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, 7 May 2026 10:52:50 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 80CB914000F0 for ; Thu, 7 May 2026 06:52:45 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Thu, 07 May 2026 06:52:45 -0400 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=1778151165; x=1778237565; bh=BISNhxDCaagLubRSyocU5zD7QaYnapFP3vNUZzAP34w=; b= Dv3mPWra8jROoDBobIX3K8ssBS1xjqdCOJfm/mlyIMzlf/nM1sVY3kA7hYoBMRj/ g1Qn2MNKEBmnCkMs7QjW7AAptgmA8J+bsswnf3MO3F2cIjwUVpEbnrDqqTWbD6nn Q6fcCa7GpCp2Nn+OHeoutNEeDsynXnBqeJnLUpQZsQAaqNIo3sDKjTKpwFlD5vyi qJj8gggfjYLQLoJN4lDPpBWIoace79dKa7Np54yrQkExuO8IZLvZeMu3hvnSnz3d l4235lcssoQ2dRRsAPBfmk32FBUwarsodDmsybwJ0s9Nr2hQkrLXk2b76ZCVkgv1 JI7FYedLxijswVYfDi7Adg== 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=1778151165; x=1778237565; bh=B ISNhxDCaagLubRSyocU5zD7QaYnapFP3vNUZzAP34w=; b=ljvdK4ZPLHVoK5mwf AQn/ew0SYOLmA8IMndh6HgWPMvvMHIbxRUCaO2GkRCCI4hSWFwFQW/WO5+1CCKQu Cg5hN39lRZnpLYUOJSzc5qdRYzaZxEd2hw7/FefjHS4LU+VBJ3z3jM4nQXY0x5ZE 7qR9GrkZcEJM5V5HSRRzdhuKZe7E/SBPUJqP2Tx6Ynv4UIiU8udV2e/CsUiDO5Ot YmSx7wOyZqFtwZw4KwzZuIQJ4wsVTgGVn/r0adi/3T6QynRpT4G3r/m1u+X2A3x4 3O1W/v4z+1fXFs6ut3J0D75Z1oiwIUk0mz/lefiiL3vrjE4RPW2iueakWgOekam6 iT6Eg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddutdejvdekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvffufggjfhfkgggtgfesthhqmhdttderjeenucfhrhhomhepfdftohifrghn ucfvohhmmhhinhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtg hordhukheqnecuggftrfgrthhtvghrnhepledvueehtdehudduleefhffgjefhffdvleej fefgueeigfeigfdvhefhfeeuvddvnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrphhh phesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthhopedupdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 7 May 2026 06:52:44 -0400 (EDT) Date: Thu, 07 May 2026 11:52:42 +0100 To: PHP internals list Subject: Re: [PHP-DEV] [RFC] Scope functions User-Agent: K-9 Mail for Android In-Reply-To: <0187D382-80FD-432C-B0D5-B0F9D8783419@hotmail.com> References: <0187D382-80FD-432C-B0D5-B0F9D8783419@hotmail.com> Message-ID: <6B83B07A-0344-4149-BFE9-7F3DD21BBA39@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 6 May 2026 21:09:45 BST, Bob Weinand wrote: >Volker and I drafted a RFC: > >https://wiki=2Ephp=2Enet/rfc/scope-functions Hi Bob,=20 An I right in thinking that this is essentially equivalent to "automatic c= apture by closure", with an extra restriction on the lifetime of the result= ing closure? It would be good to spell out in the RFC how this compares to = other approaches, and other languages=2E In particular, JavaScript's capture semantics are somewhat notorious as a = source of confusion=2E A common example is creating closures in a loop whic= h all use the same variable; as far as I can see, the proposed semantics wo= uld allow this as long as they were executed before the parent scope ends: ``` function parent_scope() { $values =3D range(1,10); $scoped_functions =3D []; foreach( $values as $v ) { $scoped_functions[] =3D fn($v) { echo "Chosen item is {$v}"; }; } =20 run_random_callable($scoped_functions); } /** * @param callable[] $callables */ function run_random_callable($callables) { $pick =3D array_rand($callables); $callables[$pick](); } // Will always output 'Chosen item is 10'! // The list of "scoped functions" will all actually refer to the same $v, = updated in the loop parent_scope(); ``` I don't know if there's some way to make the lifetime even more restricted= , so that the use cases of "immediate execution" are allowed, but this kind= of code is not=2E For something like "run this in a transaction", the closure is really acti= ng like a poor man's "continuation": it creates two new stack frames (trans= action wrapper, callback) when what you really want is to *interleave* the = boilerplate and the case-specific code=2E In that sense, hygienic macros are probably the "ideal" solution - everyth= ing is expanded inline into a single scope, and there's no Closure object w= hich can be misused=2E Context Managers could in fact be implemented as such a macro, and as I un= derstand it, the implementation is basically doing that internally by manip= ulating ASTs=2E I wonder if there's any "minimal" macro system which would allow this kind= of inline boilerplate expansion, without needing to design an entire meta-= language? Regards, Rowan Tommins [IMSoP]