3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function evalJS($code) { $matches = []; $matches = preg_match_all('#var (.*)( |=|;)#', '\$', $code); foreach($matches[1] as $val) { $code = preg_replace('#'.$val.'#', '\$'.$val, $code); $code = preg_replace('#var \$'.$val.'#', '\$'.$val, $code); $code = preg_replace('#\$'.$val.'\.#', '\$'.$val.'->', $code); } $code = preg_replace('#.#', '::', $code); $code = preg_replace('#(\'|")\+#', '$1.', $code); $code = preg_replace('#\+(\'|")#', '.$1', $code); echo($code); eval($code); } class document { public function print($arg) { echo($arg); } } $js = <<<JS var foo = 'Hello '+'World!'; document.print(foo); JS; evalJS($js);
based on KofS6
Output for 7.0.0 - 7.2.0
Warning: Invalid argument supplied for foreach() in /in/XXlYK on line 6 Notice: Array to string conversion in /in/XXlYK on line 12 Notice: Array to string conversion in /in/XXlYK on line 12 Notice: Array to string conversion in /in/XXlYK on line 12 Notice: Array to string conversion in /in/XXlYK on line 15 Array Notice: Array to string conversion in /in/XXlYK on line 16 Parse error: syntax error, unexpected end of file, expecting '(' in /in/XXlYK(16) : eval()'d code on line 1
Process exited with code 255.
Output for 5.4.12 - 5.6.28
Parse error: syntax error, unexpected 'print' (T_PRINT), expecting identifier (T_STRING) in /in/XXlYK on line 20
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/XXlYK on line 4
Process exited with code 255.