3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test(ReflectionFunctionAbstract $r) { var_dump($r->isClosure()); $dc = $r->getDeclaringClass(); var_dump($dc ? $dc->getName() : 'no declaring class'); $csc = $r->getClosureScopeClass(); var_dump($csc ? $csc->getName() : 'no closure scope class'); echo "\n\n"; } class C { function f() { return function($p) {}; } } $c = new C; $cl = $c->f(); // instantiate ReflectionFunction directly on closure $rf = new ReflectionFunction($cl); test($rf); // get ReflectionFunction via one of the initial ReflectionFunction's ReflectionParameter objects $rps = $rf->getParameters(); $rp = $rps[0]; test($rp->getDeclaringFunction());

preferences:
38.32 ms | 402 KiB | 5 Q