3v4l.org

run code in 300+ PHP versions simultaneously
<?php class WebASM { private $_input; private $_val; private $_0 = 0; private $_1 = 0; private $_2 = 0; private $_3 = 0; private $_4 = 0; private $_5 = 0; private $_6 = 0; private $_7 = 0; public function __construct($code) { $this->_0 = $code; unset($code); if(!is_string($this->_0)) { $this->_0 = 0; return 1; } if(preg_match('#^file\:#', $this->_0)) { $this->_0 = preg_replace('#^file\:#', '', $this->_0); if(file_exists($this->_0)) { $this->_0 = file_get_contents($this->_0); } else { $this->_0 = 0; return 1; } } $this->_0 = preg_replace_callback('#(.*):#', function ($matches) { if(is_numeric($matches[1])) { return 'a'.$matches[0]; } else { return '//'.$matches[0]; } }, $this->_0); $this->_0 = preg_replace('#pri?nt (.*)#', 'echo(\$this->_$1);', $this->_0); $this->_0 = preg_replace('#set ([0-7]) ([0-9]{1,256})#U', '\$this->_$1 = $2;', $this->_0); $this->_0 = preg_replace('#copyto ([0-7])#', '\$this->_$1 = \$this->_val;', $this->_0); $this->_0 = preg_replace('#copyfrom ([0-7])#', '\$this->_val = \$this->_$1;', $this->_0); //$this->_0 = preg_replace('#pro?mpt (str|int) ([0-9]{256})#', 'echo($1);', $this->_0); $this->_0 = preg_replace('#add ([0-7])#', '\$this->_val = \$this->_val + \$this->_$1;', $this->_0); $this->_0 = preg_replace('#sub ([0-7])#', '\$this->_val = \$this->_val - \$this->_$1;', $this->_0); $this->_0 = preg_replace('#jump ([0-9]{1,256}) if ([0-7]) ([0-9]{1,256})#', 'if(\$this->_$2 == $3) goto a$1;', $this->_0); $this->_0 = preg_replace('#jump ([0-9]{1,256}) if ([0-9]{1,256})#', 'if(\$this->_val == $2) goto a$1;', $this->_0); $this->_0 = preg_replace('#jump ([0-9]{1,256})#', 'goto a$1;', $this->_0); $this->_0 = preg_replace('#(die|re?tu?rn|exit)#', 'return 0;', $this->_0); $this->_0 = '$c = function () {'.$this->_0.'return 1;};$x=$c();if($x!=0)echo("An error has occured.");'; eval($this->_0); } } $code = <<<WebASM set 0 1 set 1 1 copyfrom 0 0: add 1 jump 1 if 3 jump 0 1: copyto 0 print 0 lol: print 1 WebASM; $asm = new WebASM($code);

preferences:
58.22 ms | 402 KiB | 5 Q