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

Function pack_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P48s6
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
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/P48s6
function name:  pack_decode
number of ops:  23
compiled vars:  !0 = $format, !1 = $val, !2 = $b64, !3 = $bytes
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '_'
          4        SEND_VAL                                                 '%2F'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !2, $4
   10     8        INIT_FCALL                                               'unpack'
          9        SEND_VAR                                                 !0
         10        INIT_FCALL                                               'base64_decode'
         11        SEND_VAR                                                 !2
         12        SEND_VAL                                                 <false>
         13        DO_ICALL                                         $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !3, $7
   11    17        INIT_FCALL                                               'print_r'
         18        SEND_VAR                                                 !3
         19        SEND_VAL                                                 <false>
         20        DO_ICALL                                         $9      
         21      > RETURN                                                   $9
   14    22*     > 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/P48s6
function name:  pack_encode_uint16
number of ops:  7
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'pack_encode'
          2        SEND_VAL                                                 'n'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $1      
          5      > RETURN                                                   $1
   18     6*     > RETURN                                                   null

End of function pack_encode_uint16

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

End of function pack_encode_uint32

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

End of function pack_decode_uint16

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

End of function pack_decode_uint32

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.48 ms | 1402 KiB | 33 Q