Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117671 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18690 invoked from network); 5 May 2022 12:22:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 May 2022 12:22:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D683180053 for ; Thu, 5 May 2022 06:59:53 -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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 5 May 2022 06:59:49 -0700 (PDT) Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-2f16645872fso49347887b3.4 for ; Thu, 05 May 2022 06:59:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AO6qKuxTdbgo7Os+gDi1QbStPDucOliqDHaXgSU+q8I=; b=L6t0YFuApeBaGKfNHs2WMs/h6DBRCUs56RPvS9MAxtm1xD7wvgbJ1gpVaEsrniDCeG DmADe8x4NUvgZpHM7WqeNO/N1Z32Kcx21bhhUUg0fM5Tcsd2XgY8FsiTomGXzMQbvUuH VUQT6B+0insoGOAi3h1NAI/DNs6QJYH2Eynvw3sdo7bDluV+XPv0Fiqjo24nSwvJ60+5 mcoiX2HqWh7gF3I0dpJ6g0RYjsMQ5mtQ6MpIDE8dzJmK7yPfwvvp9NE/9M/yLV/CGPtR AMdkCkCAh2Hf73xpzgB8FpmyRsH2/dyYnFrME1Xh0NCnsTEyRPYriPSQY3HrAiTkbm11 rltw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AO6qKuxTdbgo7Os+gDi1QbStPDucOliqDHaXgSU+q8I=; b=8I5jzq8d8B2km3+iFKFSz0jrL4AUlbLZqFhw/yj2mvf/dPEOt7YN9sQDqBWPAobwKN xNy+ctI6aYqmRnTh4G8zgEk1N/eJUtvt2ndf0LnrlbRMT5hR6FnnpOFwhBucuu4WEid3 q4OWMhKp8XqYu4vixbWw9xvFuJGn+yUCrjvuF/czlj6zMVhRTJo/y00KJqUOGj2PEGbm YfEjLT9UihXuyVGQR4S0u207t1cS8R40Je2fgWpQpHVoyxtjWatbEuu6nJXS3x0V9BuL JPffLoFKk08zc8vcJYS7nM3d0MzvqniBXil9z3zTI5ZYfbEKyKGTK6f3IU8v1jrKWr+B RG8w== X-Gm-Message-State: AOAM530ImMRbb/tJHooOql695pBuAkDNGNshWssoX6cEQn8xUfv9p/o7 fRhbVc4ZJmGwe4TqJ05jcF9WRVj0idJe3qdWco1NrPa1YdQ= X-Google-Smtp-Source: ABdhPJwzzCulyVexlroo4D2JBV8uTNSupnyIVnGRQ4sB8MTfnFHpFIBoTg6gy+fRVZWijrWQtA5LbwU56ZtBgnrsEcE= X-Received: by 2002:a81:2fce:0:b0:2f1:c837:8127 with SMTP id v197-20020a812fce000000b002f1c8378127mr24276322ywv.277.1651759189204; Thu, 05 May 2022 06:59:49 -0700 (PDT) MIME-Version: 1.0 References: <17c9ff9e9da.10b3e7f1c1280030.5141627710284677362@pmmp.io> <17ca83c277d.dc53327f1579308.2336162242535956459@pmmp.io> In-Reply-To: <17ca83c277d.dc53327f1579308.2336162242535956459@pmmp.io> Date: Thu, 5 May 2022 15:59:37 +0200 Message-ID: To: "Dylan K. Taylor" Cc: Claude Pache , internals Content-Type: multipart/alternative; boundary="000000000000ba244a05de442782" Subject: Re: [PHP-DEV] Add ReflectionFunctionAbstract::isAnonymous() From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000ba244a05de442782 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Le ven. 22 oct. 2021 =C3=A0 15:41, Dylan K. Taylor a =C3= =A9crit : > > ---- On Fri, 22 Oct 2021 14:19:23 +0100 Claude Pache < > claude.pache@gmail.com> wrote ---- > > > > > Le 21 oct. 2021 =C3=A0 01:12, Dylan K. Taylor a =C3= =A9crit : > > > > Hi all, > > > > Given the addition of Closure::fromCallable() and the upcoming > first-class callable syntax in 8.1, it seems slightly problematic that > there's no simple way to tell by reflection if a Closure refers to an > anonymous function or not. ReflectionFunctionAbstract::isClosure() (perha= ps > somewhat misleadingly) returns whether the closure is literally a \Closur= e > instance, so it's not useful for this purpose. > > > > 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 depends on undocumented behaviour. > > > > I'm proposing the addition of > ReflectionFunctionAbstract::isAnonymous(), which would fill this use case= , > and may be able to offer an implementation. > > > > Thanks, > > Dylan Taylor. > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > > > > > Hi, > > > > Per the manual [1], Closure::fromCallable() =E2=80=9Ccreates and retur= ns a new > anonymous function=E2=80=9D. I guess that this might not match your notio= n of > =E2=80=9Canonymous function=E2=80=9D? > > > > Therefore, I am asking for clarification: What practical distinction d= o > you make between =E2=80=9Dan instance of Closure=E2=80=9D and =E2=80=9Can= anonymous function=E2=80=9D, and > why does this distinction matter? > > > > [1]: https://www.php.net/manual/en/closure.fromcallable.php > > > > =E2=80=94Claude > > > > Hi Claude, > Sorry for the double email, my previous reply got bounced from the mailin= g > list because I replied from the wrong address. > > An anonymous function would be an unnamed function, e.g. arrow function o= r > 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 > named or an anonymous function, and currently there's no way to tell the > difference without hacks. > > The distinction is important for reflection cases, such as the one Aaron > mentioned, and also like generating a pretty name for closures in a proje= ct > I maintain [1]. > > It's a fringe use case for sure, but considering we already have > ReflectionClass->isAnonymous(), I think it makes sense. > > [1]: > https://github.com/pmmp/PocketMine-MP/blob/986b4e0651d665c72ec011542f95b4= bd9529c6a8/src/pocketmine/utils/Utils.php#L144 > > > For the record, I submitted a PR adding ReflectionFunction::isAnonymous() at https://github.com/php/php-src/pull/8499 Cheers, Nicolas --000000000000ba244a05de442782--