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, 65535, 65536, 99999, 100000, 999999, 1000000, 4294967295, 4294967296) 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 = 23, Position 2 = 28
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/Q2IYF
function name:  (null)
number of ops:  31
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   INIT_ARRAY                                       ~1      0
          1        ADD_ARRAY_ELEMENT                                ~1      1
          2        ADD_ARRAY_ELEMENT                                ~1      99
          3        ADD_ARRAY_ELEMENT                                ~1      100
          4        ADD_ARRAY_ELEMENT                                ~1      255
          5        ADD_ARRAY_ELEMENT                                ~1      256
          6        ADD_ARRAY_ELEMENT                                ~1      999
          7        ADD_ARRAY_ELEMENT                                ~1      1000
          8        ADD_ARRAY_ELEMENT                                ~1      9999
          9        ADD_ARRAY_ELEMENT                                ~1      10000
         10        FETCH_CONSTANT                                   ~2      '%C2%A065535'
         11        ADD_ARRAY_ELEMENT                                ~1      ~2
         12        FETCH_CONSTANT                                   ~3      '%C2%A065536'
         13        ADD_ARRAY_ELEMENT                                ~1      ~3
         14        ADD_ARRAY_ELEMENT                                ~1      99999
         15        ADD_ARRAY_ELEMENT                                ~1      100000
         16        ADD_ARRAY_ELEMENT                                ~1      999999
         17        ADD_ARRAY_ELEMENT                                ~1      1000000
         18        FETCH_CONSTANT                                   ~4      '%C2%A04294967295'
         19        ADD_ARRAY_ELEMENT                                ~1      ~4
         20        FETCH_CONSTANT                                   ~5      '%C2%A04294967296'
         21        ADD_ARRAY_ELEMENT                                ~1      ~5
         22      > FE_RESET_R                                       $6      ~1, ->28
         23    > > FE_FETCH_R                                               $6, !0, ->28
   32    24    >   INIT_FCALL                                               'test_enc'
         25        SEND_VAR                                                 !0
         26        DO_FCALL                                      0          
   31    27      > JMP                                                      ->23
         28    >   FE_FREE                                                  $6
   33    29        ECHO                                                     '%0A'
   44    30      > 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/Q2IYF
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/Q2IYF
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/Q2IYF
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:
159.23 ms | 1407 KiB | 26 Q