3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class interpreter { private $_code; public function __construct($code) { if(!is_string($code)) exit('Error while parsing code; Code not conformal.'); $this->_code = $code; $this->exec(); } public function parser($code = null) { $array = []; if($code === null) $code = $this->_code; if(preg_match('#print\((.*)\)#', $code, $array)) echo($array[1]); } } $code = 'print("Hello World!");'; $program = new interpreter($code);
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method interpreter::exec() in /in/mYbs5:7 Stack trace: #0 /in/mYbs5(16): interpreter->__construct('print("Hello Wo...') #1 {main} thrown in /in/mYbs5 on line 7
Process exited with code 255.
Output for 5.4.11 - 5.6.21
Fatal error: Call to undefined method interpreter::exec() in /in/mYbs5 on line 7
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/mYbs5 on line 10
Process exited with code 255.