3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 24
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 24
Branch analysis from position: 43
Branch analysis from position: 24
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 2
Branch analysis from position: 22
Branch analysis from position: 2
filename:       /in/VUccF
function name:  (null)
number of ops:  44
compiled vars:  !0 = $i, !1 = $val, !2 = $enc, !3 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->20
   27     2    >   SL                                               ~5      1, !0
          3        ASSIGN                                                   !1, ~5
   28     4        INIT_FCALL                                               'pack_encode'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !2, $7
   29     8        INIT_FCALL                                               'pack_decode'
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !3, $9
   30    12        ROPE_INIT                                     6  ~12     !1
         13        ROPE_ADD                                      1  ~12     ~12, '+%3D%3E+'
         14        ROPE_ADD                                      2  ~12     ~12, !2
         15        ROPE_ADD                                      3  ~12     ~12, '+%3D%3E+'
         16        ROPE_ADD                                      4  ~12     ~12, !3
         17        ROPE_END                                      5  ~11     ~12, '%0A'
         18        ECHO                                                     ~11
   26    19        PRE_INC                                                  !0
         20    >   IS_SMALLER                                               !0, 32
         21      > JMPNZ                                                    ~16, ->2
   33    22    >   ASSIGN                                                   !0, 1
         23      > JMP                                                      ->41
   34    24    >   INIT_FCALL                                               'pack_encode'
         25        SEND_VAR                                                 !1
         26        DO_FCALL                                      0  $18     
         27        ASSIGN                                                   !2, $18
   35    28        INIT_FCALL                                               'pack_decode'
         29        SEND_VAR                                                 !1
         30        DO_FCALL                                      0  $20     
         31        ASSIGN                                                   !3, $20
   36    32        ROPE_INIT                                     6  ~23     !2
         33        ROPE_ADD                                      1  ~23     ~23, '+'
         34        ROPE_ADD                                      2  ~23     ~23, !3
         35        ROPE_ADD                                      3  ~23     ~23, '+'
         36        ROPE_ADD                                      4  ~23     ~23, !1
         37        ROPE_END                                      5  ~22     ~23, '%0A'
         38        ECHO                                                     ~22
   33    39        SL                                               ~26     !0, 1
         40        ASSIGN                                                   !0, ~26
         41    >   IS_SMALLER                                               !0, 4294967296
         42      > JMPNZ                                                    ~28, ->24
   37    43    > > RETURN                                                   1

Function pack_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 3
Branch analysis from position: 12
Branch analysis from position: 3
filename:       /in/VUccF
function name:  pack_encode
number of ops:  22
compiled vars:  !0 = $val, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, ''
    5     2      > JMP                                                      ->10
    6     3    >   INIT_FCALL                                               'chr'
          4        BW_AND                                           ~3      !0, 255
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        ASSIGN_OP                                     8          !1, $4
    7     8        SR                                               ~6      !0, 8
          9        ASSIGN                                                   !0, ~6
    5    10    >   IS_SMALLER                                               0, !0
         11      > JMPNZ                                                    ~8, ->3
   10    12    >   INIT_FCALL                                               'str_replace'
   11    13        SEND_VAL                                                 <array>
   12    14        SEND_VAL                                                 <array>
   13    15        INIT_FCALL                                               'base64_encode'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                         $9      
         18        SEND_VAR                                                 $9
         19        DO_ICALL                                         $10     
         20      > RETURN                                                   $10
   15    21*     > RETURN                                                   null

End of function pack_encode

Function pack_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 13
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 13
Branch analysis from position: 24
Branch analysis from position: 13
filename:       /in/VUccF
function name:  pack_decode
number of ops:  26
compiled vars:  !0 = $bin, !1 = $str, !2 = $val, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'base64_decode'
          2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 '_'
          4        SEND_VAL                                                 '%2F'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
   19    10        ASSIGN                                                   !2, 0
   20    11        ASSIGN                                                   !3, 0
         12      > JMP                                                      ->21
   21    13    >   INIT_FCALL                                               'ord'
         14        FETCH_DIM_R                                      ~9      !1, !3
         15        SEND_VAL                                                 ~9
         16        DO_ICALL                                         $10     
         17        MUL                                              ~11     !3, 8
         18        SL                                               ~12     $10, ~11
         19        ASSIGN_OP                                     9          !2, ~12
   20    20        PRE_INC                                                  !3
         21    >   STRLEN                                           ~15     !1
         22        IS_SMALLER                                               !3, ~15
         23      > JMPNZ                                                    ~16, ->13
   23    24    > > RETURN                                                   !2
   24    25*     > RETURN                                                   null

End of function pack_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.68 ms | 1407 KiB | 27 Q