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; } if (!function_exists('json_encode')) { die('json_encode missing'); } $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 = 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 = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 53
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 53
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 37
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 47
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/n3Gb9
function name:  (null)
number of ops:  55
compiled vars:  !0 = $vals, !1 = $val, !2 = $enc, !3 = $dec
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'json_encode'
          2        DO_ICALL                                         $4      
          3        BOOL_NOT                                         ~5      $4
          4      > JMPZ                                                     ~5, ->6
          5    > > EXIT                                                     'json_encode+missing'
   23     6    >   ASSIGN                                                   !0, <array>
   24     7      > FE_RESET_R                                       $7      !0, ->53
          8    > > FE_FETCH_R                                               $7, !1, ->53
   25     9    >   INIT_FCALL                                               'json_encode'
         10        INIT_FCALL                                               'gdr_encode'
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !2, $9
   26    16        INIT_FCALL                                               'json_encode'
         17        INIT_FCALL                                               'gdr_decode'
         18        SEND_VAR                                                 !2
         19        DO_FCALL                                      0  $11     
         20        SEND_VAR                                                 $11
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !3, $12
   27    23        INIT_FCALL                                               'json_encode'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $14     
         26        ASSIGN                                                   !1, $14
   28    27        STRLEN                                           ~16     !2
         28        STRLEN                                           ~17     !1
         29        IS_SMALLER                                               ~17, ~16
         30      > JMPZ                                                     ~18, ->37
   29    31    >   ROPE_INIT                                     4  ~20     !2
         32        ROPE_ADD                                      1  ~20     ~20, '+'
         33        ROPE_ADD                                      2  ~20     ~20, !1
         34        ROPE_END                                      3  ~19     ~20, '+WORSE%0A'
         35        ECHO                                                     ~19
         36      > JMP                                                      ->52
   30    37    >   STRLEN                                           ~22     !2
         38        STRLEN                                           ~23     !1
         39        IS_EQUAL                                                 ~22, ~23
         40      > JMPZ                                                     ~24, ->47
   31    41    >   ROPE_INIT                                     4  ~26     !2
         42        ROPE_ADD                                      1  ~26     ~26, '+'
         43        ROPE_ADD                                      2  ~26     ~26, !1
         44        ROPE_END                                      3  ~25     ~26, '+EQUAL%0A'
         45        ECHO                                                     ~25
         46      > JMP                                                      ->52
   33    47    >   ROPE_INIT                                     4  ~29     !2
         48        ROPE_ADD                                      1  ~29     ~29, '+'
         49        ROPE_ADD                                      2  ~29     ~29, !1
         50        ROPE_END                                      3  ~28     ~29, '%0A'
         51        ECHO                                                     ~28
   24    52    > > JMP                                                      ->8
         53    >   FE_FREE                                                  $7
   35    54      > 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/n3Gb9
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/n3Gb9
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:
160.09 ms | 1398 KiB | 29 Q