3v4l.org

run code in 300+ PHP versions simultaneously
<?php function pack_encode($format, $val) { $b64 = base64_encode(pack($format, $val)); return str_replace(array('/', '='), array('_', ''), $b64); } function pack_decode($format, $val) { $b64 = str_replace('_', '/', $val); // un-padded $bytes = unpack($format, base64_decode($b64, false)); return implode($bytes, ","); //return "foo"; // return $hi << 8 | $lo; } function pack_encode_uint16($val) { return pack_encode('n', $val); } function pack_encode_uint32($val) { return pack_encode('N', $val); } function pack_decode_uint16($val) { return pack_decode('n', $val); } function pack_decode_uint32($val) { return pack_decode('N', $val); } $max = 32767; $n = 20; $step = intval($max/$n); for ($i=0; $i<=$n; $i++) { $val = $i*$step; $enc16 = pack_encode_uint16($val); $enc32 = pack_encode_uint32($val); $str = base64_encode(strval($val)); // STUPID echo "$enc16 $enc32 $str $val"; $dec16 = pack_decode_uint16($enc16); $dec32 = pack_decode_uint32($enc32); if ($dec16 != $val) { echo " $dec16 != $val"; } else if ($dec32 != $val) { echo " $dec32 != $val"; } echo "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
AAA AAAAAA MA== 0 Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/0TroX:11 Stack trace: #0 /in/0TroX(11): implode(Array, ',') #1 /in/0TroX(25): pack_decode('n', 'AAA') #2 /in/0TroX(43): pack_decode_uint16('AAA') #3 {main} thrown in /in/0TroX on line 11
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
30.36 ms | 401 KiB | 8 Q