3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gdr_encode($val) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $str = ''; while ($val > 0) { $str .= $chars[$val % $base]; $val = (int)($val / $base); } return $str; } function gdr_decode($str) { $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!='; $base = strlen($chars); $map = array(); for ($i=0; $i<$base; $i++) { $map[$chars[$i]] = $i; } echo '$str ' . print_r($str, true) . "\n"; echo 'strlen($str) ' . print_r(strlen($str), true) . "\n"; $val = 0; for ($i=0; $i<strlen($str); $i++) { $val *= $base; $char = $str[$i]; echo '$char ' . print_r($char, true) . "\n"; $k = $map[$char]; echo '$k ' . print_r($k, true) . "\n"; $val += (int)$map[$str[$i]]; echo '$val ' . print_r($val, true) . "\n"; } return $val; } //$vals = array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296); $vals = array(1); foreach ($vals as $val) { $enc = gdr_encode($val); $dec = gdr_decode($enc); if (strlen($enc) > strlen($val)) { echo "$enc $val WORSE\n"; } else if (strlen($enc) == strlen($val)) { echo "$enc $val EQUAL\n"; } else { echo "$enc $val\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 37
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 37
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/rX1YQ
function name:  (null)
number of ops:  39
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN                                                   !0, <array>
   40     1      > FE_RESET_R                                       $5      !0, ->37
          2    > > FE_FETCH_R                                               $5, !1, ->37
   41     3    >   INIT_FCALL                                               'gdr_encode'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $6      
          6        ASSIGN                                                   !2, $6
   42     7        INIT_FCALL                                               'gdr_decode'
          8        SEND_VAR                                                 !2
          9        DO_FCALL                                      0  $8      
         10        ASSIGN                                                   !3, $8
   43    11        STRLEN                                           ~10     !2
         12        STRLEN                                           ~11     !1
         13        IS_SMALLER                                               ~11, ~10
         14      > JMPZ                                                     ~12, ->21
   44    15    >   ROPE_INIT                                     4  ~14     !2
         16        ROPE_ADD                                      1  ~14     ~14, '+'
         17        ROPE_ADD                                      2  ~14     ~14, !1
         18        ROPE_END                                      3  ~13     ~14, '+WORSE%0A'
         19        ECHO                                                     ~13
         20      > JMP                                                      ->36
   45    21    >   STRLEN                                           ~16     !2
         22        STRLEN                                           ~17     !1
         23        IS_EQUAL                                                 ~16, ~17
         24      > JMPZ                                                     ~18, ->31
   46    25    >   ROPE_INIT                                     4  ~20     !2
         26        ROPE_ADD                                      1  ~20     ~20, '+'
         27        ROPE_ADD                                      2  ~20     ~20, !1
         28        ROPE_END                                      3  ~19     ~20, '+EQUAL%0A'
         29        ECHO                                                     ~19
         30      > JMP                                                      ->36
   48    31    >   ROPE_INIT                                     4  ~23     !2
         32        ROPE_ADD                                      1  ~23     ~23, '+'
         33        ROPE_ADD                                      2  ~23     ~23, !1
         34        ROPE_END                                      3  ~22     ~23, '%0A'
         35        ECHO                                                     ~22
   40    36    > > JMP                                                      ->2
         37    >   FE_FREE                                                  $5
   50    38      > RETURN                                                   1

Function gdr_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 6
Branch analysis from position: 14
Branch analysis from position: 6
filename:       /in/rX1YQ
function name:  gdr_encode
number of ops:  16
compiled vars:  !0 = $val, !1 = $chars, !2 = $base, !3 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%21%3D'
    5     2        STRLEN                                           ~5      !1
          3        ASSIGN                                                   !2, ~5
    6     4        ASSIGN                                                   !3, ''
    7     5      > JMP                                                      ->12
    8     6    >   MOD                                              ~8      !0, !2
          7        FETCH_DIM_R                                      ~9      !1, ~8
          8        ASSIGN_OP                                     8          !3, ~9
    9     9        DIV                                              ~11     !0, !2
         10        CAST                                          4  ~12     ~11
         11        ASSIGN                                                   !0, ~12
    7    12    >   IS_SMALLER                                               0, !0
         13      > JMPNZ                                                    ~14, ->6
   11    14    > > RETURN                                                   !3
   12    15*     > 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 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 31
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 31
Branch analysis from position: 65
Branch analysis from position: 31
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/rX1YQ
function name:  gdr_decode
number of ops:  67
compiled vars:  !0 = $str, !1 = $chars, !2 = $base, !3 = $map, !4 = $i, !5 = $val, !6 = $char, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%21%3D'
   16     2        STRLEN                                           ~9      !1
          3        ASSIGN                                                   !2, ~9
   17     4        ASSIGN                                                   !3, <array>
   18     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->11
   19     7    >   FETCH_DIM_R                                      ~13     !1, !4
          8        ASSIGN_DIM                                               !3, ~13
          9        OP_DATA                                                  !4
   18    10        PRE_INC                                                  !4
         11    >   IS_SMALLER                                               !4, !2
         12      > JMPNZ                                                    ~16, ->7
   22    13    >   INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 <true>
         16        DO_ICALL                                         $17     
         17        CONCAT                                           ~18     '%24str+', $17
         18        CONCAT                                           ~19     ~18, '%0A'
         19        ECHO                                                     ~19
   23    20        INIT_FCALL                                               'print_r'
         21        STRLEN                                           ~20     !0
         22        SEND_VAL                                                 ~20
         23        SEND_VAL                                                 <true>
         24        DO_ICALL                                         $21     
         25        CONCAT                                           ~22     'strlen%28%24str%29+', $21
         26        CONCAT                                           ~23     ~22, '%0A'
         27        ECHO                                                     ~23
   25    28        ASSIGN                                                   !5, 0
   26    29        ASSIGN                                                   !4, 0
         30      > JMP                                                      ->62
   27    31    >   ASSIGN_OP                                     3          !5, !2
   28    32        FETCH_DIM_R                                      ~27     !0, !4
         33        ASSIGN                                                   !6, ~27
   29    34        INIT_FCALL                                               'print_r'
         35        SEND_VAR                                                 !6
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                         $29     
         38        CONCAT                                           ~30     '%24char+', $29
         39        CONCAT                                           ~31     ~30, '%0A'
         40        ECHO                                                     ~31
   30    41        FETCH_DIM_R                                      ~32     !3, !6
         42        ASSIGN                                                   !7, ~32
   31    43        INIT_FCALL                                               'print_r'
         44        SEND_VAR                                                 !7
         45        SEND_VAL                                                 <true>
         46        DO_ICALL                                         $34     
         47        CONCAT                                           ~35     '%24k+', $34
         48        CONCAT                                           ~36     ~35, '%0A'
         49        ECHO                                                     ~36
   32    50        FETCH_DIM_R                                      ~37     !0, !4
         51        FETCH_DIM_R                                      ~38     !3, ~37
         52        CAST                                          4  ~39     ~38
         53        ASSIGN_OP                                     1          !5, ~39
   33    54        INIT_FCALL                                               'print_r'
         55        SEND_VAR                                                 !5
         56        SEND_VAL                                                 <true>
         57        DO_ICALL                                         $41     
         58        CONCAT                                           ~42     '%24val+', $41
         59        CONCAT                                           ~43     ~42, '%0A'
         60        ECHO                                                     ~43
   26    61        PRE_INC                                                  !4
         62    >   STRLEN                                           ~45     !0
         63        IS_SMALLER                                               !4, ~45
         64      > JMPNZ                                                    ~46, ->31
   35    65    > > RETURN                                                   !5
   36    66*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.4 ms | 1415 KiB | 17 Q