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 = return function () { return "Some enchanted and lovely summer evening ...\n"; }; $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->getEveningMessage; echo $first(); echo call_user_func($first; echo $obj2->getEveningMessage->__invoke();
Output for 5.4.0 - 5.4.22
Parse error: syntax error, unexpected 'return' (T_RETURN) in /in/18hZh on line 14
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected T_RETURN in /in/18hZh on line 14
Process exited with code 255.

preferences:
178.55 ms | 1395 KiB | 58 Q