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); // "/" json-encodes poorly and "=" is padding } function pack_decode($format, $width, $bin) { $b64 = str_replace('_', '/', $bin); // un-padded $data = unpack($format, base64_decode($b64, false)); $val = 0; foreach ($data as $v) { $val = ($val<<$width) | $v; } return $val; } function pack_encode_uint16($val) { return pack_encode('n', $val); } function pack_decode_uint16($val) { return pack_decode('n', 16, $val); } function pack_encode_uint32($val) { return pack_encode('N', $val); } function pack_decode_uint32($val) { return pack_decode('N', 32, $val); } function pack_encode_uint64($val) { return pack_encode('NN', $val); } function pack_decode_uint64($val) { return pack_decode('NN', 32, $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); $enc64 = pack_encode_uint64($val); $str = base64_encode(strval($val)); // STUPID echo "$enc16 $enc32 $str $val"; $dec16 = pack_decode_uint16($enc16); $dec32 = pack_decode_uint32($enc32); $dec64 = pack_decode_uint32($enc64); if ($dec16 != $val) { echo " 16($dec16 != $val)"; }if ($dec32 != $val) { echo " 32($dec32 != $val)"; } else if ($dec64 != $val) { echo " 64($dec64 != $val)"; } echo "\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught ValueError: Type N: too few arguments in /in/YG4ht:4 Stack trace: #0 /in/YG4ht(4): pack('NN', 0) #1 /in/YG4ht(35): pack_encode('NN', 0) #2 /in/YG4ht(51): pack_encode_uint64(0) #3 {main} thrown in /in/YG4ht on line 4
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:
40.38 ms | 401 KiB | 8 Q