Re: Add ReflectionFunctionAbstract::isAnonymous()

From: Date: Thu, 21 Oct 2021 21:07:26 +0000
Subject: Re: Add ReflectionFunctionAbstract::isAnonymous()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-116287@lists.php.net to get a copy of this message
> On Oct 20, 2021, at 6:12 PM, Dylan K. Taylor <dktapps@pmmp.io> wrote: > > 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() (perhaps > somewhat misleadingly) returns whether the closure is literally a \Closure 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 Dylan, I recently wrote some code checking for “{closure}”: https://github.com/amphp/amp/blob/27219ddbc0bbc3fd0db4d7380eaed6489c7291ed/lib/functions.php#L135 <https://github.com/amphp/amp/blob/27219ddbc0bbc3fd0db4d7380eaed6489c7291ed/lib/functions.php#L135> I agree, it is a bit unpleasant and looks like a hack. I would welcome an isAnonymous() method. Cheers, Aaron Piotrowski

« previous php.internals (#116287) next »