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"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 7
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 54
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 63
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 7
Branch analysis from position: 75
Branch analysis from position: 7
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 71
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 75, Position 2 = 7
Branch analysis from position: 75
Branch analysis from position: 7
Branch analysis from position: 71
Branch analysis from position: 54
filename:       /in/YG4ht
function name:  (null)
number of ops:  76
compiled vars:  !0 = $max, !1 = $n, !2 = $step, !3 = $i, !4 = $val, !5 = $enc16, !6 = $enc32, !7 = $enc64, !8 = $str, !9 = $dec16, !10 = $dec32, !11 = $dec64
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   ASSIGN                                                   !0, 32767
   44     1        ASSIGN                                                   !1, 20
   45     2        DIV                                              ~14     !0, !1
          3        CAST                                          4  ~15     ~14
          4        ASSIGN                                                   !2, ~15
   47     5        ASSIGN                                                   !3, 0
          6      > JMP                                                      ->73
   48     7    >   MUL                                              ~18     !3, !2
          8        ASSIGN                                                   !4, ~18
   49     9        INIT_FCALL                                               'pack_encode_uint16'
         10        SEND_VAR                                                 !4
         11        DO_FCALL                                      0  $20     
         12        ASSIGN                                                   !5, $20
   50    13        INIT_FCALL                                               'pack_encode_uint32'
         14        SEND_VAR                                                 !4
         15        DO_FCALL                                      0  $22     
         16        ASSIGN                                                   !6, $22
   51    17        INIT_FCALL                                               'pack_encode_uint64'
         18        SEND_VAR                                                 !4
         19        DO_FCALL                                      0  $24     
         20        ASSIGN                                                   !7, $24
   52    21        INIT_FCALL                                               'base64_encode'
         22        CAST                                          6  ~26     !4
         23        SEND_VAL                                                 ~26
         24        DO_ICALL                                         $27     
         25        ASSIGN                                                   !8, $27
   53    26        ROPE_INIT                                     7  ~30     !5
         27        ROPE_ADD                                      1  ~30     ~30, '+'
         28        ROPE_ADD                                      2  ~30     ~30, !6
         29        ROPE_ADD                                      3  ~30     ~30, '+'
         30        ROPE_ADD                                      4  ~30     ~30, !8
         31        ROPE_ADD                                      5  ~30     ~30, '+'
         32        ROPE_END                                      6  ~29     ~30, !4
         33        ECHO                                                     ~29
   55    34        INIT_FCALL                                               'pack_decode_uint16'
         35        SEND_VAR                                                 !5
         36        DO_FCALL                                      0  $34     
         37        ASSIGN                                                   !9, $34
   56    38        INIT_FCALL                                               'pack_decode_uint32'
         39        SEND_VAR                                                 !6
         40        DO_FCALL                                      0  $36     
         41        ASSIGN                                                   !10, $36
   57    42        INIT_FCALL                                               'pack_decode_uint32'
         43        SEND_VAR                                                 !7
         44        DO_FCALL                                      0  $38     
         45        ASSIGN                                                   !11, $38
   58    46        IS_NOT_EQUAL                                             !9, !4
         47      > JMPZ                                                     ~40, ->54
   59    48    >   ROPE_INIT                                     5  ~42     '+16%28'
         49        ROPE_ADD                                      1  ~42     ~42, !9
         50        ROPE_ADD                                      2  ~42     ~42, '+%21%3D+'
         51        ROPE_ADD                                      3  ~42     ~42, !4
         52        ROPE_END                                      4  ~41     ~42, '%29'
         53        ECHO                                                     ~41
   60    54    >   IS_NOT_EQUAL                                             !10, !4
         55      > JMPZ                                                     ~45, ->63
   61    56    >   ROPE_INIT                                     5  ~47     '+32%28'
         57        ROPE_ADD                                      1  ~47     ~47, !10
         58        ROPE_ADD                                      2  ~47     ~47, '+%21%3D+'
         59        ROPE_ADD                                      3  ~47     ~47, !4
         60        ROPE_END                                      4  ~46     ~47, '%29'
         61        ECHO                                                     ~46
         62      > JMP                                                      ->71
   62    63    >   IS_NOT_EQUAL                                             !11, !4
         64      > JMPZ                                                     ~50, ->71
   63    65    >   ROPE_INIT                                     5  ~52     '+64%28'
         66        ROPE_ADD                                      1  ~52     ~52, !11
         67        ROPE_ADD                                      2  ~52     ~52, '+%21%3D+'
         68        ROPE_ADD                                      3  ~52     ~52, !4
         69        ROPE_END                                      4  ~51     ~52, '%29'
         70        ECHO                                                     ~51
   66    71    >   ECHO                                                     '%0A'
   47    72        PRE_INC                                                  !3
         73    >   IS_SMALLER_OR_EQUAL                                      !3, !1
         74      > JMPNZ                                                    ~56, ->7
   67    75    > > RETURN                                                   1

Function pack_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_encode
number of ops:  17
compiled vars:  !0 = $format, !1 = $val, !2 = $b64
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'base64_encode'
          3        INIT_FCALL                                               'pack'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !2, $4
    5    10        INIT_FCALL                                               'str_replace'
         11        SEND_VAL                                                 <array>
         12        SEND_VAL                                                 <array>
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $6      
         15      > RETURN                                                   $6
    6    16*     > RETURN                                                   null

End of function pack_encode

Function pack_decode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/YG4ht
function name:  pack_decode
number of ops:  28
compiled vars:  !0 = $format, !1 = $width, !2 = $bin, !3 = $b64, !4 = $data, !5 = $val, !6 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    9     3        INIT_FCALL                                               'str_replace'
          4        SEND_VAL                                                 '_'
          5        SEND_VAL                                                 '%2F'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !3, $7
   10     9        INIT_FCALL                                               'unpack'
         10        SEND_VAR                                                 !0
         11        INIT_FCALL                                               'base64_decode'
         12        SEND_VAR                                                 !3
         13        SEND_VAL                                                 <false>
         14        DO_ICALL                                         $9      
         15        SEND_VAR                                                 $9
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !4, $10
   11    18        ASSIGN                                                   !5, 0
   12    19      > FE_RESET_R                                       $13     !4, ->25
         20    > > FE_FETCH_R                                               $13, !6, ->25
   13    21    >   SL                                               ~14     !5, !1
         22        BW_OR                                            ~15     !6, ~14
         23        ASSIGN                                                   !5, ~15
   12    24      > JMP                                                      ->20
         25    >   FE_FREE                                                  $13
   15    26      > RETURN                                                   !5
   16    27*     > RETURN                                                   null

End of function pack_decode

Function pack_encode_uint16:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_encode_uint16
number of ops:  7
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'pack_encode'
          2        SEND_VAL                                                 'n'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   20     6*     > RETURN                                                   null

End of function pack_encode_uint16

Function pack_decode_uint16:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_decode_uint16
number of ops:  8
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        INIT_FCALL                                               'pack_decode'
          2        SEND_VAL                                                 'n'
          3        SEND_VAL                                                 16
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $1      
          6      > RETURN                                                   $1
   24     7*     > RETURN                                                   null

End of function pack_decode_uint16

Function pack_encode_uint32:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_encode_uint32
number of ops:  7
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        INIT_FCALL                                               'pack_encode'
          2        SEND_VAL                                                 'N'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   28     6*     > RETURN                                                   null

End of function pack_encode_uint32

Function pack_decode_uint32:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_decode_uint32
number of ops:  8
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        INIT_FCALL                                               'pack_decode'
          2        SEND_VAL                                                 'N'
          3        SEND_VAL                                                 32
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $1      
          6      > RETURN                                                   $1
   32     7*     > RETURN                                                   null

End of function pack_decode_uint32

Function pack_encode_uint64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_encode_uint64
number of ops:  7
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_FCALL                                               'pack_encode'
          2        SEND_VAL                                                 'NN'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   36     6*     > RETURN                                                   null

End of function pack_encode_uint64

Function pack_decode_uint64:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YG4ht
function name:  pack_decode_uint64
number of ops:  8
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
   39     1        INIT_FCALL                                               'pack_decode'
          2        SEND_VAL                                                 'NN'
          3        SEND_VAL                                                 32
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $1      
          6      > RETURN                                                   $1
   40     7*     > RETURN                                                   null

End of function pack_decode_uint64

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.68 ms | 1415 KiB | 35 Q