3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestClass { function getClosure() { return function () { var_dump($this); } } } $abc = "testABC"; $xyz = new TestClass(); $test = true; $x = function () use ($test, $xyz, $abc) { echo $abc; var_dump($test, $xyz); var_dump($this); }; $test = new TestClass(); echo packAnonFunction($x, $test, $xyz, $abc); echo packAnonFunction($test->getClosure()); function packAnonFunction($payload, ...$args) { $func = new ReflectionFunction($payload); $filename = $func->getFileName(); $start_line = $func->getStartLine() - 1; $end_line = $func->getEndLine(); $length = $end_line - $start_line; var_dump($func->getClosureThis()); $source = file($filename); $body = implode("", array_slice($source, $start_line, $length)); $body = preg_replace('/(?:(?:(\$[a-z]+)\s\=)|return)\sfunction/', '\\$payload = function', $body); if(preg_match('/use\s\((\$[a-zA-Z0-9]+(?:,\s\$[a-zA-Z0-9]+)*)\)/', $body, $matches)) { $vars = $matches[1]; if(strpos($vars, ', ') !== false) { $parts = explode(', ', $vars); } else { $parts = [$vars]; } $body = str_replace(" use (" . $vars . ")", "", $body); } else { $parts = []; } if(strpos($body, '$this') !== false) { $parts[] = '$this'; $args[count($parts) - 1] = $func->getClosureThis(); } $return = []; foreach($parts as $key => $variable) { $return[$variable] = $args[$key]; } $variableString = ""; foreach($return as $var => $value) { $value = serialize($value); $variableString .= "\t{$var} = unserialize('{$value}');\n"; } $body = str_replace("{\n", "{\n" . $variableString, $body); return $body; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.0.00.0030.09720.24
5.6.160.0070.08020.55
5.6.150.0170.07018.25
5.6.140.0130.07018.18
5.6.130.0000.04318.18
5.6.120.0100.05321.15
5.6.110.0130.07721.00
5.6.100.0070.08720.89
5.6.90.0030.09321.11
5.6.80.0170.07720.37
5.5.300.0130.05017.92
5.5.290.0030.05017.99
5.5.280.0130.07020.86
5.5.270.0070.07020.98
5.5.260.0030.04320.96
5.5.250.0030.08720.62
5.5.240.0200.07720.13

preferences:
142.14 ms | 1394 KiB | 7 Q