3v4l.org

run code in 300+ PHP versions simultaneously
<?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->parser(); } public function parser($code = null) { if($code === null) $code = $this->_code; $calls = []; $variables = []; $conditions = []; preg_match('#(.*)\((.*)\)#', $code, $calls); preg_match('#if\((.*)\) \{(.*)\}#s', $code, $conditions); if($conditions && isset($conditions[0])) $this->conditions_ifelse($conditions); if($calls && isset($calls[0])) $this->calls($calls); } private function calls(array $calls) { switch($calls[1]) { case 'print': $this->func_print($calls[2]); break; } } private function condition_ifelse(array $conditions) { if(!preg_match('#(.*)(==|===|\<|\<=|\>|\>=|!=|!==|&&|\|\||AND|OR|XOR)(.*)#i', $conditions[1])) exit('Condition parsing error.'); } } abstract class lang { const version = 0.1; } class console extends lang { } class out extends console { public function println($arg) { if(preg_match('#^("|\')(.*)("|\')$#', $arg)) $arg = preg_replace('#^("|\')(.*)("|\')$#', '$2', $arg); echo($arg); } } $code = <<<CODE int var = 1; if(var == 1) { console.out.println("Hello World!"); } else { console.out.println("Hi!"); } CODE; $program = new interpreter($code);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Call to undefined method interpreter::conditions_ifelse() in /in/uth5B:16 Stack trace: #0 /in/uth5B(7): interpreter->parser() #1 /in/uth5B(49): interpreter->__construct('int var = 1;\nif...') #2 {main} thrown in /in/uth5B on line 16
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:
58.46 ms | 401 KiB | 8 Q