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.' };$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 exit WebASM; $asm = new WebASM($code);
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
31
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 31

preferences:
188.13 ms | 401 KiB | 210 Q