3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function pack_encode($val) { $str = ''; while ($val > 0) { $str .= chr($val & 0xFF); $val = $val >> 8; } // "/" json-encodes poorly and "=" is padding return str_replace( array('/', '='), array('_', ''), base64_encode($str) ); } function pack_decode($bin) { $str = base64_decode(str_replace('_', '/', $bin)); $val = 0; for ($i=0; $i<strlen($str); $i++) { $val |= (ord($str[$i]) << ($i * 8)); } return $val; } for ($i=0; $i<32; $i++) { $val = 1<<$i; $enc = pack_encode($val); $dec = pack_decode($enc); echo "$val => $enc => $dec\n"; } for ($i=1; $i < (1<<32); $i = $($i<<1)) { $enc = pack_encode($val); $dec = pack_decode($val); echo "$enc $dec $val\n"; }
based on LsDF0
Output for 5.4.0 - 5.4.31
Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' in /in/6VbIo on line 33
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.28
Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in /in/6VbIo on line 33
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '(', expecting T_VARIABLE or '$' in /in/6VbIo on line 33
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/6VbIo on line 33
Process exited with code 255.