3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ClosureInATrait { public static function getClosureInTrait() { return function () { return __CLASS__; }; } } class ClassConstantTest { use ClosureInATrait; public static function getClosureInClass() { return function () { return __CLASS__; }; } } $closureInClass = ClassConstantTest::getClosureInClass(); $closureInTrait = ClassConstantTest::getClosureInTrait(); echo 'Before bind: ' . PHP_EOL; echo '__CLASS__ in class: ' . PHP_EOL; var_dump($closureInClass()); echo '__CLASS__ in Trait: ' . PHP_EOL; var_dump($closureInTrait()); $closureInClass = Closure::bind($closureInClass, $closureInClass, 'stdClass'); $closureInTrait = Closure::bind($closureInTrait, $closureInClass, 'stdClass'); echo PHP_EOL . 'After bind: ' . PHP_EOL; echo '__CLASS__ in class: ' . PHP_EOL; var_dump($closureInClass()); echo '__CLASS__ in Trait: ' . PHP_EOL; var_dump($closureInTrait());
Output for git.master, git.master_jit, rfc.property-hooks
Before bind: __CLASS__ in class: string(17) "ClassConstantTest" __CLASS__ in Trait: string(17) "ClassConstantTest" Warning: Cannot bind closure to scope of internal class stdClass in /in/APTaS on line 34 Warning: Cannot bind closure to scope of internal class stdClass in /in/APTaS on line 35 After bind: __CLASS__ in class: Fatal error: Uncaught Error: Value of type null is not callable in /in/APTaS:39 Stack trace: #0 {main} thrown in /in/APTaS on line 39
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:
38.76 ms | 401 KiB | 8 Q