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; } function test_enc($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"; } } foreach (array(0, 1, 99, 100, 255, 256, 999, 1000, 9999, 10000) as $val) { test_enc($val); } echo "\n"; // seed rng for consistent values if (phpversion() < '5.2.1') { die('old rng'); } mt_srand(42); for ($i=0; $i<63; $i++) { $val = 1<<$i; $val += mt_rand(0, $val/2); test_enc($val); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 1, Position 2 = 6
Branch analysis from position: 1
2 jumps found. (Code = 78) Position 1 = 2, Position 2 = 6
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 1
Branch analysis from position: 1
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 79) Position 1 = -2
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 = 32, Position 2 = 18
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 18
Branch analysis from position: 32
Branch analysis from position: 18
Branch analysis from position: 6
filename:       /in/PftrC
function name:  (null)
number of ops:  33
compiled vars:  !0 = $val, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E > > FE_RESET_R                                       $2      <array>, ->6
          1    > > FE_FETCH_R                                               $2, !0, ->6
   32     2    >   INIT_FCALL                                               'test_enc'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0          
   31     5      > JMP                                                      ->1
          6    >   FE_FREE                                                  $2
   34     7        ECHO                                                     '%0A'
   37     8        INIT_FCALL                                               'phpversion'
          9        DO_ICALL                                         $4      
         10        IS_SMALLER                                               $4, '5.2.1'
         11      > JMPZ                                                     ~5, ->13
         12    > > EXIT                                                     'old+rng'
   38    13    >   INIT_FCALL                                               'mt_srand'
         14        SEND_VAL                                                 42
         15        DO_ICALL                                                 
   40    16        ASSIGN                                                   !1, 0
         17      > JMP                                                      ->30
   41    18    >   SL                                               ~8      1, !1
         19        ASSIGN                                                   !0, ~8
   42    20        INIT_FCALL                                               'mt_rand'
         21        SEND_VAL                                                 0
         22        DIV                                              ~10     !0, 2
         23        SEND_VAL                                                 ~10
         24        DO_ICALL                                         $11     
         25        ASSIGN_OP                                     1          !0, $11
   43    26        INIT_FCALL                                               'test_enc'
         27        SEND_VAR                                                 !0
         28        DO_FCALL                                      0          
   40    29        PRE_INC                                                  !1
         30    >   IS_SMALLER                                               !1, 63
         31      > JMPNZ                                                    ~15, ->18
   44    32    > > 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/PftrC
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/PftrC
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

Function test_enc:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PftrC
function name:  test_enc
number of ops:  27
compiled vars:  !0 = $val, !1 = $enc, !2 = $dec, !3 = $valĀ ERROR
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        INIT_FCALL                                               'gdr_encode'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   23     5        INIT_FCALL                                               'gdr_decode'
          6        SEND_VAR                                                 !1
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   24     9        IS_IDENTICAL                                             !0, !2
         10      > JMPZ                                                     ~8, ->17
   25    11    >   ROPE_INIT                                     4  ~10     !1
         12        ROPE_ADD                                      1  ~10     ~10, '+'
         13        ROPE_ADD                                      2  ~10     ~10, !0
         14        ROPE_END                                      3  ~9      ~10, '%0A'
         15        ECHO                                                     ~9
         16      > JMP                                                      ->26
   27    17    >   ROPE_INIT                                     8  ~13     !1
         18        ROPE_ADD                                      1  ~13     ~13, '+'
         19        ROPE_ADD                                      2  ~13     ~13, !3
         20        ROPE_ADD                                      3  ~13     ~13, '%3A+gdr_decode%28'
         21        ROPE_ADD                                      4  ~13     ~13, !1
         22        ROPE_ADD                                      5  ~13     ~13, '%29+%3D%3D+'
         23        ROPE_ADD                                      6  ~13     ~13, !2
         24        ROPE_END                                      7  ~12     ~13, '%0A'
         25        ECHO                                                     ~12
   29    26    > > RETURN                                                   null

End of function test_enc

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.45 ms | 1411 KiB | 33 Q