Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130977 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 336631A00BC for ; Wed, 20 May 2026 21:02:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1779310933; bh=hctt8cJUdyawuYih7nHc98Z6qYSZ+U9Oon3T5Z2FJ2k=; h=Date:To:From:Subject:From; b=OONPCPvIw/lecVVBnOt27ManyJKYWfLYPE28Ev7fo2LHnx86dN/lsmmQwsBD1c+XK b20Gc9eG5yIDoYmb+RHBIctugtFUK7Q3K0g9LeVtb8NrpPFeW8QRHHes6mYwVk/BC+ IBcGbe5wfIIK5WGzJXZfooX0m6GGiuK+6RK6NDSbxTbr0/vK7Vwgp3Wsk6QRaJMsF9 lMeGxJ/2ECyT/kdjCshzDZ7RbyEXNOkNxfhoE51h/0Yl7JDrcjaRssnzCYaEkHuyYW uqJ875Xgix4cUJ66dxQc8jNIYdQGMvxf4hMJf40PFHUNfPJf0EvtTvuETZYxas2Hwr m87XWtWjD2Tyw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C1AC818005A for ; Wed, 20 May 2026 21:02:11 +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_PASS,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 mail-4399.protonmail.ch (mail-4399.protonmail.ch [185.70.43.99]) (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 ; Wed, 20 May 2026 21:02:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mountainofcode.co.uk; s=protonmail; t=1779310914; x=1779570114; bh=hctt8cJUdyawuYih7nHc98Z6qYSZ+U9Oon3T5Z2FJ2k=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=bk24dCf5uouIelkkatzwS7sXtWZ3jDXhcJSQuaCxK31ah8dmb0P/djB2f1MaB6P9Y 6B3Y3PIXU83r3RgqLIg1s+TCai/cJgb2UeaOiHicT/VASa7pbOPoa/On1Q6ZsESh/v VxgR14yvSWdyBW5zRZ9EMObTCRUuretkc8Mno+gwhqtOF0rI1DOt0RuFE3x9+JvUv0 K5gO0BJ2RU2xejJtrc5iicXuszLMrDiCqSf3jqbiRT1h+lZbu5V7irxvSnS6Hrfl6S rjIZLfcqT5yaKxegIzY9U/2B2jXa+n1OfLzHh6s7w8DeUxEKV/3C+Dy8wb5++/GNQO 9JwfYvZO3tuGw== Date: Wed, 20 May 2026 21:01:51 +0000 To: internals@lists.php.net Subject: [PHP-DEV] Re: [RFC] Scope functions Message-ID: Feedback-ID: 198683275:user:proton X-Pm-Message-ID: 21be4bbeaf55a92a0a63f3821cebb039554bf0ff 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: php@mountainofcode.co.uk (MCode) On Thu, 07 May 2026 15:19:01 +0000, Alex Rock wrote: > Thanks for this RFC, here are my 2cents: > > I think the current syntax is too close to current short closures, and > since it allows multiline closures, it would imply that by default all > multiline short closures are scoped, which is not intuitive since > traditional closures don't capture by default. > Instead, I think replacing the `fn () { }`=C2=A0 syntax to add a keyboar= d > indicating it inherits the scope would drastically help making it more > intuitive. > > I would imagine instead something like this: > > =C2=A0 =C2=A0 $externalVar =3D 0; > =C2=A0 =C2=A0 $closure1 =3D scoped fn () =3D> $newVar1 =3D $externalVar+= +; > =C2=A0 =C2=A0 $closure2 =3D scoped function () { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 return $newVar2 =3D $externalVar++; > =C2=A0 =C2=A0 }; > =C2=A0 =C2=A0 $closure1(); > =C2=A0 =C2=A0 $closure2(); > =C2=A0 =C2=A0 var_dump($newVar1); // int(0) > =C2=A0 =C2=A0 var_dump($newVar2); // int(1) > =C2=A0 =C2=A0 var_dump($externalVar); // int(2) > > This way, for the first case, the only new information that `scoped` > brings is the potential existence of `$newVar1` after the closure's > execution, and for the second closure, it makes it explicit that all > variables in the closure's body are shared with the parent scope. > > WDYT? > > Le 06/05/2026 =C3=A0 22:09, Bob Weinand a =C3=A9crit=C2=A0: > > Volker and I drafted a RFC: > > > > https://wiki.php.net/rfc/scope-functions > > > > Please consider it and share your feedback. > > > > I hope it will alleviate pain around some of the most common forms of > > Closure usage which is "execute this now as part of the called > > function", which currently can require a lot of "use ($variables)". > > > > For me the primary use case of use ($capturing) was always "I need > > this function later and want to explicitly document what escapes my > > function". This, however, required this straightforward usage of > > Closures to also document every single usage of a variable. Which is > > really not that beneficial at all. > > > > Thus the scope functions as proposed will be able to fill that gap in > > future. > > > > Thank you, > > Bob I agree that the new syntax is too close to current short closures. I don't think we need a new keyword though, I think the presence of `=3D>`= =20 in the function definition should indicate that scope is captured, like=20 this: ``` function() =3D> { =C2=A0 =C2=A0 // ... } ``` To put it another way `fn() =3D> foo;` would be a syntactically identical= =20 version of `function() =3D> {return foo;}`