Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127110 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 qa.php.net (Postfix) with ESMTPS id 5A85B1A00BC for ; Tue, 15 Apr 2025 07:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744702749; bh=1zbnQI+0fw5qEEBqpa/OYOqT6oqLD2oQlWwvdx11voA=; h=Date:From:To:Subject:In-Reply-To:References:From; b=RykQwxeAgicGpHTXr3/4dHbub7xk4xfrze8xSQeoIuOGCYj9swGdKnC5OC2lTzgtn x4VdAuUcjWwQ1X9CHfBfeNm1n2rOQ4QiE12zxN6ZIMtaelsMGdJmOL+q6fBhbiLFN0 k55oYzBNnfy0H70W6WlMmTajkR5t8zfvo2d18Dpbu89H6RoPGTt85Ly9s9QVG5gOpp Z9tutnVAdmYd/w9c8yiHcgtwoeuT1BuaioUlgCPurFOEEmOqo6r9dnf0Vg71H7qkHs iev2lkpAd3Fy8sUlsUuLtmwqlk9x3PtH3/Dn3i4ybviVjf9+z215U2vh9zOWg0jL66 5KvCwaQez1yBA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA192180074 for ; Tue, 15 Apr 2025 07:39:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) 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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (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, 15 Apr 2025 07:39:08 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 311231140222 for ; Tue, 15 Apr 2025 03:41:30 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 15 Apr 2025 03:41:30 -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=fm2; t=1744702890; x=1744789290; bh=XxAQkhP5zYPmCHnlL5npW1Po6HQrTSEPdJwq3YKd0U0=; b= f0+Ts88WXrDyHEqPAk+Nkf7fnGW+OJdrN+kYpKbMGzj/uCIWAkPMm6CtQe8bf0uO bj4xqygdUkaiBOAtsYgcHCcDBn/SFhcrtpUGB7dq3U7jvjSxOpOdLTnBhmxYk80T TFhKsO1pQmMyntycq/C/1jBSBzAKg+lCJ2t2q1bO4VuRc9r0rcvSQYvuL3ZjDC5N dt6rd2/UHBiFuq81ewuzUVnb0aogurb07EsFFs37AQvpA12Zpj1kMQLmpw3+TjyQ 6BHFza4JGG61uHOTw+U+MX4gBwPFuOBrdZC968jEIVDXU0cS3JXOy5fqFoG5KqUG S1Mvo1j0rxiuBRfiQ9SVHA== 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=fm2; t=1744702890; x=1744789290; bh=X xAQkhP5zYPmCHnlL5npW1Po6HQrTSEPdJwq3YKd0U0=; b=NIVwzlF6BJIC2GdyF 5d0twMX2ay0NZC2w2mtd7EsjXEh9AFCdK3Tb10mzcGSX0v3iF9EejmeRTkGsRKp5 z4Jw6xoZmF/H6+eb2vgu6v900XzEx9w9U+MYtsEGXNCXkIJnlTIO0nZqbk2n7Jsj 2tzCvdAhAL+kssQQkKyiVpxJQo+37XYYucN6NKbVXUdt8P5do/gdtoI1re+O6egr 0bRPUdv72JwQI+PCCMPjH1u7H4gWcoNpffRRQGZtglFYK+NbGzcrWv8dV2aLqRwI 2bf9O48of8piytFDPjPz968gfNsxMN1BQEKOa+P1aplmeBELFlKKVZ2aIFxV0FsD RxGjw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvvddvkeelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpeffhf fvufgfjghfkfggtgfgsegrjehmredtreejnecuhfhrohhmpedftfhofigrnhcuvfhomhhm ihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqe enucggtffrrghtthgvrhhnpeeuffffvefffeehgfelgedtvefgvdfgheetjedthedvveeg jeejudduieeuheefhfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhukhdpnhgspghrtghpthht ohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsheslh hishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 15 Apr 2025 03:41:29 -0400 (EDT) Date: Tue, 15 Apr 2025 08:41:28 +0100 To: internals@lists.php.net Subject: Re: [PHP-DEV] Closure::getCurrent() for recursion User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <933A6600-F9E3-4335-B496-972EB0037CD2@rwec.co.uk> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: multipart/alternative; boundary=----B1XYNZOKAABAO7N7V0MV3881ELRLAQ Content-Transfer-Encoding: 7bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") ------B1XYNZOKAABAO7N7V0MV3881ELRLAQ Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 15 April 2025 00:01:18 BST, Krinkle wrote: >Eg: >=20 >$a =3D function ($a) { > $aFn =3D Closure::current(=2E=2E=2E); > $aFn(4) =3D=3D=3D Closure::current(4); >}; I think there's some confusion on this thread; as I understand it, the pro= posal is not for a magic function to *call* the current closure, but a way = to get a *reference to it*=2E So you don't need, or want, the FCC syntax here - that would create a clos= ure which, whenever invoked, executes the static method "current" on class = "Closure"=2E What you want is to call the Closure::current (or getCurrent) method direc= tly, which will give you the existing closure, known as $a in the outer sco= pe=2E Once you have a reference to it, you can pass it around and execute i= t wherever you want=2E $aOutside =3D function (int $foo) use (&$aOutside) { // Points to the same object as if you used by-ref assert($aOutside =3D=3D=3D Closure::getCurrent()); // Store it wherever you like=20 $aInside =3D Closure::getCurrent(); assert($aInside =3D=3D=3D $aOutside); =20 // Call it like you would any callable=20 $aOutside(42); $aInside(42); Closure::getCurrent()(42); // note the two sets of parens // Capture it into another closure $bOutside =3D function() use ($aInside) { // Get a self-reference in that one too=20 $bInside =3D Closure::getCurrent(); // Do whatever you like with $aInside and $bInside }; }; Rowan Tommins [IMSoP] ------B1XYNZOKAABAO7N7V0MV3881ELRLAQ Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On 15 April 2025 00:01:18 BST,= Krinkle <krinkle@fastmail=2Ecom> wrote:

>Eg:
>
&= gt;$a =3D function ($a) {
>=C2=A0 $aFn =3D Closure::current(=2E=2E=2E= );
>=C2=A0 $aFn(4) =3D=3D=3D Closure::current(4);
>};

I = think there's some confusion on this thread; as I understand it, the propos= al is not for a magic function to *call* the current closure, but a way to = get a *reference to it*=2E

So you don't need, or want, the FCC synta= x here - that would create a closure which, whenever invoked, executes the = static method "current" on class "Closure"=2E

What you want is to ca= ll the Closure::current (or getCurrent) method directly, which will give yo= u the existing closure, known as $a in the outer scope=2E Once you have a r= eference to it, you can pass it around and execute it wherever you want=2E<= br>
$aOutside =3D function (int $foo) use (&$aOutside) {
=C2=A0 /= / Points to the same object as if you used by-ref
=C2=A0 assert($aOutsid= e =3D=3D=3D Closure::getCurrent());
=C2=A0 // Store it wherever you like=
=C2=A0 $aInside =3D Closure::getCurrent();
=C2=A0 assert($aInside = =3D=3D=3D $aOutside);

=C2=A0 // Call it like you would any callable=
=C2=A0 $aOutside(42);
=C2=A0 $aInside(42);
=C2=A0 Closure::getCu= rrent()(42); // note the two sets of parens

=C2=A0=C2=A0 // Capture = it into another closure
=C2=A0=C2=A0 $bOutside =3D function() use ($aIns= ide) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // Get a self-reference in that on= e too
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 $bInside =3D Closure::getCurrent()= ;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // Do whatever you like with $aInside a= nd $bInside
=C2=A0=C2=A0 };
};

Rowan T= ommins
[IMSoP]
------B1XYNZOKAABAO7N7V0MV3881ELRLAQ--