Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127109 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 3C97A1A00BC for ; Mon, 14 Apr 2025 23:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744671558; bh=b6gGUHJeEduQnyVizr8L+gmQz978tQ0X0qD76YpriLY=; h=Date:From:To:In-Reply-To:References:Subject:From; b=LD2HA9VqeJ5eKncj08g8j+9wVnQxCHeQ7Syau0wChyMYTVh82LbBs6uu+Qq+8Bg4i LYm8FI5wzxYSNdQdbJNWIkNezi9CQxdABTuqdMWjHNZm/sSJ9RyDLIYQ7RSS3tIg5d 8DJeqBfMpgLJPZLEfscAf5NZYkTu5inpsvAYXggUIKnN1FZIjq3WCzDj3OfgqE8+0A ncIhwr4UTW/JxBEvZI1eZkA25fjNDlcSdvf6ah+WA1gvHLY7Zt0dz8k8ctO8YSddFT lFA+e7g0qf5bJbbLYXE9Wk1FlZWw8cdCy4r60oi+Zg4KTW9IwYp/xe/EYRC8vWSLBV /JbjHZ1D7P8HQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE41D18004F for ; Mon, 14 Apr 2025 22:59:17 +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_PASS,FREEMAIL_FROM, 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-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (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 ; Mon, 14 Apr 2025 22:59:17 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 9755C1140258 for ; Mon, 14 Apr 2025 19:01:39 -0400 (EDT) Received: from phl-imap-10 ([10.202.2.85]) by phl-compute-12.internal (MEProxy); Mon, 14 Apr 2025 19:01:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc: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=1744671699; x=1744758099; bh=Ime4E3urDA pdvXZAnjWPHhq01xQjUKoO1B1SjIOw6Qw=; b=UTr9WKq0QagsMqA9MUOxQG0ECg r56hNYLYIvfTaWEMWv1jseeP2VdrX+AZRsf9xHJAbL9mvH+nBPbmMhSPtuI06Bbl aUbxpB+gRvm06/ThT8PqGtUlxGl7iUWDn0oK7CCF+TVpw5zMdCsdwAMOUjd9YiH2 K/SDkg4HI5FAOC5NQvANyChmN2Ye/0HE7RmoDHnzOUy2xwuYjPVM4iOyr0a282gh EwMuLOAIkGXAp8sSog7miCI+6t+RknNfg+mC9xJb3w0XmNSmMuh1ObB7znkWjhJb q/GEBGicLQsnICtYDJzSkNJjmi1dZ2AIk+PYI9y9mgG9iCJXeuOea1PNjZLA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= 1744671699; x=1744758099; bh=Ime4E3urDApdvXZAnjWPHhq01xQjUKoO1B1 SjIOw6Qw=; b=G9zCZAFr3ukYZg3/IrMVxLPwAf11sRBxp6Yqzo1zeXzmX2D1d9n pSb65nGn6b7lNrZw//gSpNpGE+XCY8NPZjhm3GhDYQ1NxpuIK7qZyZ0BlWlZGodp mU/PmOou2IHnA0hoDOkv+zfvxV6X3TKJIzguT0ZqHcW+AIxGrqnkcWrsCiVGzmPi 0CCQW9rlFKAR+DLRiTxuijkvsmG/Q6qRmMu5YIzqnwvR6r5km95b5xXH39LDK9i1 swi5ksgbBdEyscYjneJ0M6jBA5np+SWMeBFCB2bxIq/H7/uadL9sp85uOM+EKOIS CA2Qj1oCX++prcaSzl4z7Om5PWZmIuGWvjA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvvddukedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtsegrtderreertddt necuhfhrohhmpefmrhhinhhklhgvuceokhhrihhnkhhlvgesfhgrshhtmhgrihhlrdgtoh hmqeenucggtffrrghtthgvrhhnpefgieehhfefiefghfegffduteejhfekhffgtdekheek vdekhefhgfdugfekhfdugeenucffohhmrghinhepphhhphdrnhgvthdpthhimhhothhijh hhohhfrdhnvghtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomhepkhhrihhnkhhlvgesfhgrshhtmhgrihhlrdgtohhmpdhnsggprhgtphhtthhope dupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhs thhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i7dd1477f:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 2887E3C0068; Mon, 14 Apr 2025 19:01:39 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T1fc05e61e19584d2 Date: Tue, 15 Apr 2025 00:01:18 +0100 To: "PHP internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] Closure::getCurrent() for recursion Content-Type: multipart/alternative; boundary=ecbf66a5065447c2b1ea09a50157b519 From: krinkle@fastmail.com (Krinkle) --ecbf66a5065447c2b1ea09a50157b519 Content-Type: text/plain Content-Transfer-Encoding: 7bit On Mon, 31 Mar 2025, Jorg Sowa wrote: > I thought about edge cases and what the desired output is with nested closures? > > Example: > $a = function (int $numberA) { > $b = function (int $numberB) { > if($numberB < 10) { > return Closure::current(10); > } > return $numberB; > }; > return $b($numberA) + $numberA; > }; > > var_dump($a(4)); I'd expect it to refer to current/local/nearest function. If you wanted a way to call $a from inside $b, I'd expect callable syntax to be able to capture these in-place. Eg: $a = function ($a) { $aFn = Closure::current(...); $aFn(4) === Closure::current(4); }; https://www.php.net/manual/en/functions.first_class_callable_syntax.php This could be use'd to a nested $b function, or otherwise passed/returned to other functions without changing meaning. That is, I would not expect it to behave like late-static binding where it'll always be for the "current" fn that's invoking it, but rather capture where the callable expression happened. -- Timo Tijhof, Wikimedia Foundation. https://timotijhof.net/ --ecbf66a5065447c2b1ea09a50157b519 Content-Type: text/html Content-Transfer-Encoding: quoted-printable
On Mon, 31 Mar = 2025, Jorg Sowa wrote:
I thought about edge case= s and what the desired output is with nested closures?

Example:
<?
$a =3D function (int $n= umberA) {
    $b =3D function (int $numberB) {
=
        if($numberB < 10) {
 =           return Closure::current(10);
        }
      &nb= sp; return $numberB;
    };
    = return $b($numberA) + $numberA;
};

va= r_dump($a(4));

I'd exp= ect it to refer to current/local/nearest function.

<= div>If you wanted a way to call $a from inside $b, I'd expect callable s= yntax to be able to capture these in-place.

Eg:=
 
$a =3D function ($a) {
  $aFn= =3D Closure::current(...);
  $aFn(4) =3D=3D=3D Clos= ure::current(4);
};







= --ecbf66a5065447c2b1ea09a50157b519--