3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $input = '((800 + 20) - 800 / 2)'; $tokens = token_get_all("<?php {$input}"); $expr = ''; foreach($tokens as $token){ print "$token[1]"; if(is_string($token)){ if(in_array($token, array('(', ')', '+', '-', '/', '*'), true)) $expr .= $token; continue; } list($id, $text) = $token; if(in_array($id, array(T_DNUMBER, T_LNUMBER))) $expr .= $text; } eval("\$result = {$expr};"); print "\nexpr = " . $expr; print "\nres = " . $result;
Output for 5.2.10 - 7.1.0
<?php Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 800 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 20 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 800 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 2 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 expr = ((800+20)-800/2) res = 420
Output for 4.3.0 - 5.2.9
<?php Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 800 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 20 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 800 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 2 Notice: Uninitialized string offset: 1 in /in/O7reB on line 10 expr = ((800+20)-800/2) res = 420