3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $bin = ''; while ($val > 0) { $bin .= chr($val & 0xFF); $val >>= 8; } return str_replace(array('/', '='), array('_', ''), base64_encode($bin)); } function gdr_decode($str) { $bin = base64_decode(str_replace('_', '/', $str)); $val = 0; for ($i=strlen($bin)-1; $i>=0; $i--) { $val |= ord($bin[$i]) << $i*8; } return $val; } $vals = array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if ($val === $dec) { echo "$enc $val\n"; } else { echo "$enc $valĀ ERROR: gdr_decode($enc) == $dec\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 29
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 29
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/DUODu
function name:  (null)
number of ops:  31
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec, !4 = $valĀ ERROR
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   22     1      > FE_RESET_R                                       $6      !0, ->29
          2    > > FE_FETCH_R                                               $6, !1, ->29
   23     3    >   INIT_FCALL                                               'gdr_encode'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $7      
          6        ASSIGN                                                   !2, $7
   24     7        INIT_FCALL                                               'gdr_decode'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
   25    11        IS_IDENTICAL                                             !1, !3
         12      > JMPZ                                                     ~11, ->19
   26    13    >   ROPE_INIT                                     4  ~13     !2
         14        ROPE_ADD                                      1  ~13     ~13, '+'
         15        ROPE_ADD                                      2  ~13     ~13, !1
         16        ROPE_END                                      3  ~12     ~13, '%0A'
         17        ECHO                                                     ~12
         18      > JMP                                                      ->28
   28    19    >   ROPE_INIT                                     8  ~16     !2
         20        ROPE_ADD                                      1  ~16     ~16, '+'
         21        ROPE_ADD                                      2  ~16     ~16, !4
         22        ROPE_ADD                                      3  ~16     ~16, '%3A+gdr_decode%28'
         23        ROPE_ADD                                      4  ~16     ~16, !2
         24        ROPE_ADD                                      5  ~16     ~16, '%29+%3D%3D+'
         25        ROPE_ADD                                      6  ~16     ~16, !3
         26        ROPE_END                                      7  ~15     ~16, '%0A'
         27        ECHO                                                     ~15
   22    28    > > JMP                                                      ->2
         29    >   FE_FREE                                                  $6
   30    30      > RETURN                                                   1

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

End of function gdr_encode

Function gdr_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 15
Branch analysis from position: 25
Branch analysis from position: 15
filename:       /in/DUODu
function name:  gdr_decode
number of ops:  27
compiled vars:  !0 = $str, !1 = $bin, !2 = $val, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     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
   14    10        ASSIGN                                                   !2, 0
   15    11        STRLEN                                           ~8      !1
         12        SUB                                              ~9      ~8, 1
         13        ASSIGN                                                   !3, ~9
         14      > JMP                                                      ->23
   16    15    >   INIT_FCALL                                               'ord'
         16        FETCH_DIM_R                                      ~11     !1, !3
         17        SEND_VAL                                                 ~11
         18        DO_ICALL                                         $12     
         19        MUL                                              ~13     !3, 8
         20        SL                                               ~14     $12, ~13
         21        ASSIGN_OP                                     9          !2, ~14
   15    22        PRE_DEC                                                  !3
         23    >   IS_SMALLER_OR_EQUAL                                      0, !3
         24      > JMPNZ                                                    ~17, ->15
   18    25    > > RETURN                                                   !2
   19    26*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.07 ms | 1407 KiB | 25 Q