3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fn = function () { return get_called_class(); }; var_dump((new ReflectionFunction($fn))->getClosureScopeClass()); class C { private static $test = 'In class C'; public function __construct() { $fn = function () { return get_called_class(); }; $res = (new ReflectionFunction($fn))->getClosureScopeClass(); var_dump(get_class($res)); var_dump($res->getName()); } public static function s_fn() { $fn = function () { var_dump(D::$test); return get_called_class(); }; $res = (new ReflectionFunction($fn))->getClosureScopeClass(); var_dump(get_class($res)); var_dump($res->getName()); return $fn; } } class D extends C { private static $test = 'In class D'; public function __construct() { static::s_fn(); } public static function test() { return static::s_fn(); } } $d = new D; $func = D::test(); var_dump($func());
Output for git.master, git.master_jit, rfc.property-hooks
NULL string(15) "ReflectionClass" string(1) "C" string(15) "ReflectionClass" string(1) "C" Fatal error: Uncaught Error: Cannot access private property D::$test in /in/o1LIU:16 Stack trace: #0 /in/o1LIU(36): C::{closure}() #1 {main} thrown in /in/o1LIU on line 16
Process exited with code 255.

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:
47.83 ms | 401 KiB | 8 Q