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 print_r($map, false) . "\n"; $val = 0; echo print_r($str, false) . "\n"; for ($i=0; $i<strlen($str); $i++) { $val *= $base; $char = $str[$i]; //echo "{$str[$i]}\n"; $val += (int)$map[$str[$i]]; } 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 = json_encode(gdr_encode($val)); $dec = json_encode(gdr_decode($enc)); $val = json_encode($val); 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 = 47
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 47
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 41
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/rihF8
function name:  (null)
number of ops:  49
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   ASSIGN                                                   !0, <array>
   35     1      > FE_RESET_R                                       $5      !0, ->47
          2    > > FE_FETCH_R                                               $5, !1, ->47
   36     3    >   INIT_FCALL                                               'json_encode'
          4        INIT_FCALL                                               'gdr_encode'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $6      
          7        SEND_VAR                                                 $6
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !2, $7
   37    10        INIT_FCALL                                               'json_encode'
         11        INIT_FCALL                                               'gdr_decode'
         12        SEND_VAR                                                 !2
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                         $10     
         16        ASSIGN                                                   !3, $10
   38    17        INIT_FCALL                                               'json_encode'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !1, $12
   39    21        STRLEN                                           ~14     !2
         22        STRLEN                                           ~15     !1
         23        IS_SMALLER                                               ~15, ~14
         24      > JMPZ                                                     ~16, ->31
   40    25    >   ROPE_INIT                                     4  ~18     !2
         26        ROPE_ADD                                      1  ~18     ~18, '+'
         27        ROPE_ADD                                      2  ~18     ~18, !1
         28        ROPE_END                                      3  ~17     ~18, '+WORSE%0A'
         29        ECHO                                                     ~17
         30      > JMP                                                      ->46
   41    31    >   STRLEN                                           ~20     !2
         32        STRLEN                                           ~21     !1
         33        IS_EQUAL                                                 ~20, ~21
         34      > JMPZ                                                     ~22, ->41
   42    35    >   ROPE_INIT                                     4  ~24     !2
         36        ROPE_ADD                                      1  ~24     ~24, '+'
         37        ROPE_ADD                                      2  ~24     ~24, !1
         38        ROPE_END                                      3  ~23     ~24, '+EQUAL%0A'
         39        ECHO                                                     ~23
         40      > JMP                                                      ->46
   44    41    >   ROPE_INIT                                     4  ~27     !2
         42        ROPE_ADD                                      1  ~27     ~27, '+'
         43        ROPE_ADD                                      2  ~27     ~27, !1
         44        ROPE_END                                      3  ~26     ~27, '%0A'
         45        ECHO                                                     ~26
   35    46    > > JMP                                                      ->2
         47    >   FE_FREE                                                  $5
   46    48      > 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/rihF8
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 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 22
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 22
Branch analysis from position: 33
Branch analysis from position: 22
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/rihF8
function name:  gdr_decode
number of ops:  35
compiled vars:  !0 = $str, !1 = $chars, !2 = $base, !3 = $map, !4 = $i, !5 = $val, !6 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ASSIGN                                                   !1, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789%21%3D'
   16     2        STRLEN                                           ~8      !1
          3        ASSIGN                                                   !2, ~8
   17     4        ASSIGN                                                   !3, <array>
   18     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->11
   19     7    >   FETCH_DIM_R                                      ~12     !1, !4
          8        ASSIGN_DIM                                               !3, ~12
          9        OP_DATA                                                  !4
   18    10        PRE_INC                                                  !4
         11    >   IS_SMALLER                                               !4, !2
         12      > JMPNZ                                                    ~15, ->7
   22    13    >   ASSIGN                                                   !5, 0
   23    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 <false>
         17        DO_ICALL                                         $17     
         18        CONCAT                                           ~18     $17, '%0A'
         19        ECHO                                                     ~18
   24    20        ASSIGN                                                   !4, 0
         21      > JMP                                                      ->30
   25    22    >   ASSIGN_OP                                     3          !5, !2
   26    23        FETCH_DIM_R                                      ~21     !0, !4
         24        ASSIGN                                                   !6, ~21
   28    25        FETCH_DIM_R                                      ~23     !0, !4
         26        FETCH_DIM_R                                      ~24     !3, ~23
         27        CAST                                          4  ~25     ~24
         28        ASSIGN_OP                                     1          !5, ~25
   24    29        PRE_INC                                                  !4
         30    >   STRLEN                                           ~28     !0
         31        IS_SMALLER                                               !4, ~28
         32      > JMPNZ                                                    ~29, ->22
   30    33    > > RETURN                                                   !5
   31    34*     > RETURN                                                   null

End of function gdr_decode

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.8 ms | 1407 KiB | 19 Q