3v4l.org

run code in 300+ PHP versions simultaneously
<?php $digits = array(0,1,2,3,4,5,6,7,7,8,9,'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); $base = count($digits); function enc($val) { $str = ''; if (0 === $val) { return '0'; } if (0 > $val) { $str = '-'; $val = -$val; } $digits = $GLOBALS['digits']; $base = $GLOBALS['base']; while (0 < $val) { $str .= $digits[$val % $base]; $val = (int)($val / $base); } return $str; } 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')) { // crappy json_encode function that can handle our narrow input function json_encode($val) { if (is_string($val)) { return "\"$val\""; } if (is_int($val)) { return strval($val); } return "???"; } } $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); $enc2 = json_encode(enc($val)); if (strlen($enc) > strlen($val)) { echo "$enc $val $enc2 WORSE\n"; } else if (strlen($enc) == strlen($val)) { echo "$enc $val $enc2 EQUAL\n"; } else { echo "$enc $val $enc2\n"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 69
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 69
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 49
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 61
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 68
Branch analysis from position: 68
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
Branch analysis from position: 9
filename:       /in/kM6kl
function name:  (null)
number of ops:  71
compiled vars:  !0 = $digits, !1 = $base, !2 = $vals, !3 = $val, !4 = $enc, !5 = $dec, !6 = $enc2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        COUNT                                            ~8      !0
          2        ASSIGN                                                   !1, ~8
   42     3        INIT_FCALL                                               'function_exists'
          4        SEND_VAL                                                 'json_encode'
          5        DO_ICALL                                         $10     
          6        BOOL_NOT                                         ~11     $10
          7      > JMPZ                                                     ~11, ->9
   44     8    >   DECLARE_FUNCTION                                         'json_encode'
   51     9    >   ASSIGN                                                   !2, <array>
   52    10      > FE_RESET_R                                       $13     !2, ->69
         11    > > FE_FETCH_R                                               $13, !3, ->69
   53    12    >   INIT_FCALL                                               'json_encode'
         13        INIT_FCALL                                               'gdr_encode'
         14        SEND_VAR                                                 !3
         15        DO_FCALL                                      0  $14     
         16        SEND_VAR                                                 $14
         17        DO_ICALL                                         $15     
         18        ASSIGN                                                   !4, $15
   54    19        INIT_FCALL                                               'json_encode'
         20        INIT_FCALL                                               'gdr_decode'
         21        SEND_VAR                                                 !4
         22        DO_FCALL                                      0  $17     
         23        SEND_VAR                                                 $17
         24        DO_ICALL                                         $18     
         25        ASSIGN                                                   !5, $18
   55    26        INIT_FCALL                                               'json_encode'
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                         $20     
         29        ASSIGN                                                   !3, $20
   56    30        INIT_FCALL                                               'json_encode'
         31        INIT_FCALL                                               'enc'
         32        SEND_VAR                                                 !3
         33        DO_FCALL                                      0  $22     
         34        SEND_VAR                                                 $22
         35        DO_ICALL                                         $23     
         36        ASSIGN                                                   !6, $23
   57    37        STRLEN                                           ~25     !4
         38        STRLEN                                           ~26     !3
         39        IS_SMALLER                                               ~26, ~25
         40      > JMPZ                                                     ~27, ->49
   58    41    >   ROPE_INIT                                     6  ~29     !4
         42        ROPE_ADD                                      1  ~29     ~29, '+'
         43        ROPE_ADD                                      2  ~29     ~29, !3
         44        ROPE_ADD                                      3  ~29     ~29, '+'
         45        ROPE_ADD                                      4  ~29     ~29, !6
         46        ROPE_END                                      5  ~28     ~29, '+WORSE%0A'
         47        ECHO                                                     ~28
         48      > JMP                                                      ->68
   59    49    >   STRLEN                                           ~32     !4
         50        STRLEN                                           ~33     !3
         51        IS_EQUAL                                                 ~32, ~33
         52      > JMPZ                                                     ~34, ->61
   60    53    >   ROPE_INIT                                     6  ~36     !4
         54        ROPE_ADD                                      1  ~36     ~36, '+'
         55        ROPE_ADD                                      2  ~36     ~36, !3
         56        ROPE_ADD                                      3  ~36     ~36, '+'
         57        ROPE_ADD                                      4  ~36     ~36, !6
         58        ROPE_END                                      5  ~35     ~36, '+EQUAL%0A'
         59        ECHO                                                     ~35
         60      > JMP                                                      ->68
   62    61    >   ROPE_INIT                                     6  ~40     !4
         62        ROPE_ADD                                      1  ~40     ~40, '+'
         63        ROPE_ADD                                      2  ~40     ~40, !3
         64        ROPE_ADD                                      3  ~40     ~40, '+'
         65        ROPE_ADD                                      4  ~40     ~40, !6
         66        ROPE_END                                      5  ~39     ~40, '%0A'
         67        ECHO                                                     ~39
   52    68    > > JMP                                                      ->11
         69    >   FE_FREE                                                  $13
   64    70      > RETURN                                                   1

Function enc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
Branch analysis from position: 17
Branch analysis from position: 10
filename:       /in/kM6kl
function name:  enc
number of ops:  27
compiled vars:  !0 = $val, !1 = $str, !2 = $digits, !3 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, ''
    8     2        IS_IDENTICAL                                             !0, 0
          3      > JMPZ                                                     ~5, ->5
    9     4    > > RETURN                                                   '0'
   11     5    >   IS_SMALLER                                               !0, 0
          6      > JMPZ                                                     ~6, ->10
   12     7    >   ASSIGN                                                   !1, '-'
   13     8        MUL                                              ~8      !0, -1
          9        ASSIGN                                                   !0, ~8
   15    10    >   FETCH_R                      global              ~10     'GLOBALS'
         11        FETCH_DIM_R                                      ~11     ~10, 'digits'
         12        ASSIGN                                                   !2, ~11
   16    13        FETCH_R                      global              ~13     'GLOBALS'
         14        FETCH_DIM_R                                      ~14     ~13, 'base'
         15        ASSIGN                                                   !3, ~14
   17    16      > JMP                                                      ->23
   18    17    >   MOD                                              ~16     !0, !3
         18        FETCH_DIM_R                                      ~17     !2, ~16
         19        ASSIGN_OP                                     8          !1, ~17
   19    20        DIV                                              ~19     !0, !3
         21        CAST                                          4  ~20     ~19
         22        ASSIGN                                                   !0, ~20
   17    23    >   IS_SMALLER                                               0, !0
         24      > JMPNZ                                                    ~22, ->17
   21    25    > > RETURN                                                   !1
   22    26*     > RETURN                                                   null

End of function enc

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/kM6kl
function name:  gdr_encode
number of ops:  21
compiled vars:  !0 = $val, !1 = $bin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   25     1        ASSIGN                                                   !1, ''
   26     2      > JMP                                                      ->9
   27     3    >   INIT_FCALL                                               'chr'
          4        BW_AND                                           ~3      !0, 255
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        ASSIGN_OP                                     8          !1, $4
   28     8        ASSIGN_OP                                     7          !0, 8
   26     9    >   IS_SMALLER                                               0, !0
         10      > JMPNZ                                                    ~7, ->3
   30    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
   31    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/kM6kl
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
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     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
   35    10        ASSIGN                                                   !2, 0
   36    11        STRLEN                                           ~8      !1
         12        SUB                                              ~9      ~8, 1
         13        ASSIGN                                                   !3, ~9
         14      > JMP                                                      ->23
   37    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
   36    22        PRE_DEC                                                  !3
         23    >   IS_SMALLER_OR_EQUAL                                      0, !3
         24      > JMPNZ                                                    ~17, ->15
   39    25    > > RETURN                                                   !2
   40    26*     > RETURN                                                   null

End of function gdr_decode

Function %00json_encode%2Fin%2FkM6kl%3A44%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kM6kl
function name:  json_encode
number of ops:  13
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~1, ->7
          3    >   ROPE_INIT                                     3  ~3      '%22'
          4        ROPE_ADD                                      1  ~3      ~3, !0
          5        ROPE_END                                      2  ~2      ~3, '%22'
          6      > RETURN                                                   ~2
   46     7    >   TYPE_CHECK                                   16          !0
          8      > JMPZ                                                     ~5, ->11
          9    >   CAST                                          6  ~6      !0
         10      > RETURN                                                   ~6
   47    11    > > RETURN                                                   '%3F%3F%3F'
   48    12*     > RETURN                                                   null

End of function %00json_encode%2Fin%2FkM6kl%3A44%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.08 ms | 1415 KiB | 30 Q