3v4l.org

run code in 300+ PHP versions simultaneously
<?php function test(ReflectionFunctionAbstract $r) { echo 'isClosure(): '; var_dump($r->isClosure()); if ($r instanceof ReflectionMethod) { $rc = $r->getDeclaringClass(); $dc = $rc ? $rc->getName() : 'no declaring class'; } else { $dc = 'not a ReflectionMethod'; } echo 'getDeclaringClass(): ' . $dc; echo "\n"; $csc = $r->getClosureScopeClass(); echo 'getClosureScopeClass(): ' . ($csc ? $csc->getName() : 'no closure scope class'); echo "\n"; echo "\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());
Output for git.master, git.master_jit, rfc.property-hooks
isClosure(): bool(true) getDeclaringClass(): not a ReflectionMethod getClosureScopeClass(): C isClosure(): bool(true) getDeclaringClass(): C getClosureScopeClass(): C

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.9 ms | 401 KiB | 8 Q