3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ClosureInATrait { public static function getClosureInTrait() { return function () { return [__CLASS__, self::boo()]; }; } public static function boo() { return __METHOD__; } } class ClassConstantTest { use ClosureInATrait; public static function getClosureInClass() { return function () { return [__CLASS__, self::class]; }; } public static function boo() { return __METHOD__; } } $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, null, 'stdClass'); $closureInTrait = Closure::bind($closureInTrait, null, '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: array(2) { [0]=> string(17) "ClassConstantTest" [1]=> string(17) "ClassConstantTest" } __CLASS__ in Trait: array(2) { [0]=> string(17) "ClassConstantTest" [1]=> string(22) "ClassConstantTest::boo" } Warning: Cannot bind closure to scope of internal class stdClass in /in/RXI8l on line 44 Warning: Cannot bind closure to scope of internal class stdClass in /in/RXI8l on line 45 After bind: __CLASS__ in class: Fatal error: Uncaught Error: Value of type null is not callable in /in/RXI8l:49 Stack trace: #0 {main} thrown in /in/RXI8l on line 49
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:
50.07 ms | 402 KiB | 8 Q