3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $input = '((\'rats\' + \'stoats\') - 800 / 2)'; $tokens = token_get_all("<? php {$input}"); $expr = ''; foreach($tokens as $token){ if(is_string($token)){ if(in_array($token, array('(', ')', '+', '-', '/', '*'), true)){ $expr .= $token; print "\n symbol: " . $expr; } continue; } list($id, $text) = $token; if(in_array($id, array(T_DNUMBER, T_LNUMBER,T_CONSTANT_ENCAPSED_STRING))){ $expr .= $text; print "\n number: " . $expr; } } eval("\$result = {$expr};"); print "\nexpr = " . $expr; print "\nres = " . $result;
Output for 7.1.0
symbol: ( symbol: (( number: (('rats' symbol: (('rats'+ number: (('rats'+'stoats' symbol: (('rats'+'stoats') symbol: (('rats'+'stoats')- number: (('rats'+'stoats')-800 symbol: (('rats'+'stoats')-800/ number: (('rats'+'stoats')-800/2 symbol: (('rats'+'stoats')-800/2) Warning: A non-numeric value encountered in /in/fZKEH(28) : eval()'d code on line 1 Warning: A non-numeric value encountered in /in/fZKEH(28) : eval()'d code on line 1 expr = (('rats'+'stoats')-800/2) res = -400
Output for 5.4.0 - 7.0.14
symbol: ( symbol: (( number: (('rats' symbol: (('rats'+ number: (('rats'+'stoats' symbol: (('rats'+'stoats') symbol: (('rats'+'stoats')- number: (('rats'+'stoats')-800 symbol: (('rats'+'stoats')-800/ number: (('rats'+'stoats')-800/2 symbol: (('rats'+'stoats')-800/2) expr = (('rats'+'stoats')-800/2) res = -400
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected ';' in /in/fZKEH(28) : eval()'d code on line 1 expr = Notice: Undefined variable: result in /in/fZKEH on line 31 res =
Process exited with code 255.
Output for 5.0.4 - 5.0.5
Parse error: parse error, unexpected ';' in /in/fZKEH(28) : eval()'d code on line 1 expr = Notice: Undefined variable: result in /in/fZKEH on line 31 res =
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.3
Parse error: parse error, unexpected ';' in /in/fZKEH(28) : eval()'d code on line 1 expr = Notice: Undefined variable: result in /in/fZKEH on line 31 res =
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected ';' in /in/fZKEH(28) : eval()'d code on line 1 expr = Notice: Undefined variable: result in /in/fZKEH on line 31 res =
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/fZKEH(28) : eval()'d code on line 1 expr = Notice: Undefined variable: result in /in/fZKEH on line 31 res =
Process exited with code 255.