3v4l.org

run code in 300+ PHP versions simultaneously
<?php // objects, closures, stdClass, clone $closures = array(); $simple_closure = function() { return $this->msg;}; for ($x=0; $x < 2; $x++) { $closures[$x] = $simple_closure; } $obj1 = new stdClass; $obj1->msg = "Top of the morning\n"; $obj1->getEveningMessage = function () { return "Some enchanted and lovely summer evening ...\n"; }; $obj1->getClosure = function() { return self::getEveningMessage; }; $obj2 = clone($obj1); $obj2->msg = "Happy Days!\n"; $c1 = Closure::bind($closures[0], $obj1); $c2 = Closure::bind($closures[1], $obj2); echo $c1(); echo $c2(); $first = $obj1->getClosure; echo $first(); echo call_user_func($first); echo $obj1->getClosure->__invoke();
Output for git.master, git.master_jit, rfc.property-hooks
Top of the morning Happy Days! Fatal error: Uncaught Error: Cannot access "self" when no class scope is active in /in/TLN9E:15 Stack trace: #0 /in/TLN9E(29): {closure}() #1 {main} thrown in /in/TLN9E on line 15
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:
34.42 ms | 401 KiB | 8 Q