note 128012 added to reflectionfunction.isanonymous
| From: | nicolasgrekas@php.net | Date: | Tue, 13 Dec 2022 10:00:30 +0000 |
| Subject: | note 128012 added to reflectionfunction.isanonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219968@lists.php.net to get a copy of this message | ||
Closures can be either anonymous or not.
Here is an anonymous closure:
$c1 = function () {};
And here is a *non* anonymous closure:
$c2 = Closure::fromCallable(['Foo', 'bar']);
ReflectionFunction::isAnonymous() returns true for $c1 and false for $c2.
Before PHP 8.2, one had to do this check to decide between both:
$r = new \ReflectionFunction($c1);
$isAnonymous = false !== strpos($r->name, '{closure}');
ReflectionFunction::isAnonymous() makes it easier to check.
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.175 (proxied: 37.170.229.139)
----
Manual Page -- https://php.net/manual/en/reflectionfunction.isanonymous.php
Edit -- https://main.php.net/note/edit/128012
Del: integrated -- https://main.php.net/note/delete/128012/integrated
Del: useless -- https://main.php.net/note/delete/128012/useless
Del: bad code -- https://main.php.net/note/delete/128012/bad+code
Del: spam -- https://main.php.net/note/delete/128012/spam
Del: non-english -- https://main.php.net/note/delete/128012/non-english
Del: in docs -- https://main.php.net/note/delete/128012/in+docs
Del: other reasons-- https://main.php.net/note/delete/128012
Reject -- https://main.php.net/note/reject/128012
Search -- https://main.php.net/manage/user-notes.php