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()); $a = new \stdClass(); $closureInClass = Closure::bind($closureInClass, null, $a); $closureInTrait = Closure::bind($closureInTrait, null, $a); 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/5vgBc on line 35 Warning: Cannot bind closure to scope of internal class stdClass in /in/5vgBc on line 36 After bind: __CLASS__ in class: Fatal error: Uncaught Error: Value of type null is not callable in /in/5vgBc:40 Stack trace: #0 {main} thrown in /in/5vgBc on line 40
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:
42.37 ms | 402 KiB | 8 Q