3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Base64Url { /** * @param $str string * * @return string */ public static function encode($str) { $std = @base64_encode($str); if ($std === false) { throw new \Exception('base64_encode() failed'); } return rtrim(strtr($std, '+/', '-_'), '='); } /** * @param $str string * * @return string */ public static function decode($str) { $result = ''; if ($str !== null) { if (!is_string($str)) { throw new \Exception('Only strings can be decoded'); } $std = strtr($data, '-_', '+/').str_repeat('=', strlen($data) % 4); $result = base64_decode($std, true); if ($result === false) { throw new \Exception('base64_decode() failed'); } } return $result; } } $ph = '{"typ":"JWT","alg":"HS256"}'; echo Base64Url::encode($ph);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DOchc
function name:  (null)
number of ops:  6
compiled vars:  !0 = $ph
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, '%7B%22typ%22%3A%22JWT%22%2C%22alg%22%3A%22HS256%22%7D'
   45     1        INIT_STATIC_METHOD_CALL                                  'Base64Url', 'encode'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Class Base64Url:
Function encode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DOchc
function name:  encode
number of ops:  24
compiled vars:  !0 = $str, !1 = $std
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        BEGIN_SILENCE                                    ~2      
          2        INIT_FCALL                                               'base64_encode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        END_SILENCE                                              ~2
          6        ASSIGN                                                   !1, $3
   14     7        TYPE_CHECK                                    4          !1
          8      > JMPZ                                                     ~5, ->13
   15     9    >   NEW                                              $6      'Exception'
         10        SEND_VAL_EX                                              'base64_encode%28%29+failed'
         11        DO_FCALL                                      0          
         12      > THROW                                         0          $6
   18    13    >   INIT_FCALL                                               'rtrim'
         14        INIT_FCALL                                               'strtr'
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 '%2B%2F'
         17        SEND_VAL                                                 '-_'
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        SEND_VAL                                                 '%3D'
         21        DO_ICALL                                         $9      
         22      > RETURN                                                   $9
   19    23*     > RETURN                                                   null

End of function encode

Function decode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 35
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/DOchc
function name:  decode
number of ops:  37
compiled vars:  !0 = $str, !1 = $result, !2 = $std, !3 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        ASSIGN                                                   !1, ''
   29     2        TYPE_CHECK                                  1020          !0
          3      > JMPZ                                                     ~5, ->35
   30     4    >   TYPE_CHECK                                   64  ~6      !0
          5        BOOL_NOT                                         ~7      ~6
          6      > JMPZ                                                     ~7, ->11
   31     7    >   NEW                                              $8      'Exception'
          8        SEND_VAL_EX                                              'Only+strings+can+be+decoded'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $8
   33    11    >   INIT_FCALL                                               'strtr'
         12        SEND_VAR                                                 !3
         13        SEND_VAL                                                 '-_'
         14        SEND_VAL                                                 '%2B%2F'
         15        DO_ICALL                                         $10     
         16        INIT_FCALL                                               'str_repeat'
         17        SEND_VAL                                                 '%3D'
         18        STRLEN                                           ~11     !3
         19        MOD                                              ~12     ~11, 4
         20        SEND_VAL                                                 ~12
         21        DO_ICALL                                         $13     
         22        CONCAT                                           ~14     $10, $13
         23        ASSIGN                                                   !2, ~14
   34    24        INIT_FCALL                                               'base64_decode'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !1, $16
   35    29        TYPE_CHECK                                    4          !1
         30      > JMPZ                                                     ~18, ->35
   36    31    >   NEW                                              $19     'Exception'
         32        SEND_VAL_EX                                              'base64_decode%28%29+failed'
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $19
   40    35    > > RETURN                                                   !1
   41    36*     > RETURN                                                   null

End of function decode

End of class Base64Url.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.3 ms | 1405 KiB | 23 Q