Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116293 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32147 invoked from network); 22 Oct 2021 12:52:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Oct 2021 12:52:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 082F6180382 for ; Fri, 22 Oct 2021 06:41:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS2639 136.143.188.0/23 X-Spam-Virus: No X-Envelope-From: Received: from sender4-of-o54.zoho.com (sender4-of-o54.zoho.com [136.143.188.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 22 Oct 2021 06:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634910088; cv=none; d=zohomail.com; s=zohoarc; b=Y8GL6WqvbywrHU3qNn3h4W5e5lsZLrVgCbVEjIsRhundohhqX/E1NNmH/e4bHLjgDjJbsURIfvQTGc73Rg/ctp6GLCDD6N0AQ2qF/B3b0+d6+uL1cUQ5gEEA9L8FxyL6pWNbH/BrxCs0wIO701/U3UTQR0n5xcLeFpw9O+knhDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634910088; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=4Odu2PvWwtur9xc8AZI33TBM+p9okaHGX0no9+V1Mx4=; b=ki2327tmIiBVFCoqJ06E2IE5R9/LoQo6SPGHJjxd+JXWA0WAVyFVBORvNa4nutEqaIYZY3RAs6w078HGuKtwYqylsMrnOMRhr+tkmpBjWFFq5c5X6ZEFd8qOc5zKdXAjS+Lpya2E6O8V/o9oYdAPTXeky+ltc0M72KO9te5SVrU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=pmmp.io; spf=pass smtp.mailfrom=dktapps@pmmp.io; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1634910088; s=verify; d=pmmp.io; i=dktapps@pmmp.io; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=4Odu2PvWwtur9xc8AZI33TBM+p9okaHGX0no9+V1Mx4=; b=Qn4ZC78KhsygHgSd+yyj4uu26U2ut5hbquqx/lXZA98etpNNxsErRTEpRj61RKXW wlBIwhSDphBicsYu9J1LzJ8PzK1O7vSRoigazv2u9acDIIEcarkOt4WmSxNjFIKRBP3 +otPmAJwIdglRwrJki1F5nyN4KZKDs+5+I03XqxU= Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1634910087077570.5193530640412; Fri, 22 Oct 2021 06:41:27 -0700 (PDT) Date: Fri, 22 Oct 2021 14:41:27 +0100 To: "Claude Pache" Cc: "internals" Message-ID: <17ca83c277d.dc53327f1579308.2336162242535956459@pmmp.io> In-Reply-To: References: <17c9ff9e9da.10b3e7f1c1280030.5141627710284677362@pmmp.io> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail Subject: Re: [PHP-DEV] Add ReflectionFunctionAbstract::isAnonymous() From: dktapps@pmmp.io ("Dylan K. Taylor") ---- On Fri, 22 Oct 2021 14:19:23 +0100 Claude Pache wrote ---- >=20 > Le 21 oct. 2021 =C3=A0 01:12, Dylan K. Taylor a =C3=A9= crit : >=20 > Hi all,=20 >=20 > Given the addition of Closure::fromCallable() and the upcoming first-cla= ss callable syntax in 8.1, it seems slightly problematic that there's no si= mple way to tell by reflection if a Closure refers to an anonymous function= or not. ReflectionFunctionAbstract::isClosure() (perhaps somewhat misleadi= ngly) returns whether the closure is literally a \Closure instance, so it's= not useful for this purpose.=20 >=20 > The only way to do this currently (that I know about) is to check if the= name of the function contains "{closure}", which is a bit unpleasant and d= epends on undocumented behaviour.=20 >=20 > I'm proposing the addition of ReflectionFunctionAbstract::isAnonymous(),= which would fill this use case, and may be able to offer an implementation= .=20 >=20 > Thanks,=20 > Dylan Taylor.=20 >=20 >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >=20 >=20 >=20 > Hi, >=20 > Per the manual [1], Closure::fromCallable() =E2=80=9Ccreates and returns= a new anonymous function=E2=80=9D. I guess that this might not match your = notion of =E2=80=9Canonymous function=E2=80=9D? >=20 > Therefore, I am asking for clarification: What practical distinction do = you make between =E2=80=9Dan instance of Closure=E2=80=9D and =E2=80=9Can a= nonymous function=E2=80=9D, and why does this distinction matter? >=20 > [1]: https://www.php.net/manual/en/closure.fromcallable.php >=20 > =E2=80=94Claude >=20 Hi Claude,=20 Sorry for the double email, my previous reply got bounced from the mailing = list because I replied from the wrong address. An anonymous function would be an unnamed function, e.g. arrow function or = function(){}. I guess the documentation for Closure::fromCallable() ought to be updated, = because Closure::fromCallable('namedFunc') isn't really anonymous, it's a \= Closure object that refers to a named function. A \Closure may refer to a n= amed or an anonymous function, and currently there's no way to tell the dif= ference without hacks. The distinction is important for reflection cases, such as the one Aaron me= ntioned, and also like generating a pretty name for closures in a project I= maintain [1]. It's a fringe use case for sure, but considering we already have Reflection= Class->isAnonymous(), I think it makes sense. [1]: https://github.com/pmmp/PocketMine-MP/blob/986b4e0651d665c72ec011542f9= 5b4bd9529c6a8/src/pocketmine/utils/Utils.php#L144 Dylan