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($str, '-_', '+/').str_repeat('=', strlen($str) % 4); $result = base64_decode($std, true); if ($result === false) { throw new \Exception('base64_decode() failed'); } } return $result; } } $ph = '{"typ":"JWT",' . "\n ". '"alg":"HS256"}'; echo Base64Url::decode(Base64Url::encode($ph));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pBKf2
function name:  (null)
number of ops:  9
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%0A+%22alg%22%3A%22HS256%22%7D'
   45     1        INIT_STATIC_METHOD_CALL                                  'Base64Url', 'decode'
          2        INIT_STATIC_METHOD_CALL                                  'Base64Url', 'encode'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_FCALL                                      0  $3      
          7        ECHO                                                     $3
          8      > 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/pBKf2
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/pBKf2
function name:  decode
number of ops:  37
compiled vars:  !0 = $str, !1 = $result, !2 = $std
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                                                     ~4, ->35
   30     4    >   TYPE_CHECK                                   64  ~5      !0
          5        BOOL_NOT                                         ~6      ~5
          6      > JMPZ                                                     ~6, ->11
   31     7    >   NEW                                              $7      'Exception'
          8        SEND_VAL_EX                                              'Only+strings+can+be+decoded'
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $7
   33    11    >   INIT_FCALL                                               'strtr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 '-_'
         14        SEND_VAL                                                 '%2B%2F'
         15        DO_ICALL                                         $9      
         16        INIT_FCALL                                               'str_repeat'
         17        SEND_VAL                                                 '%3D'
         18        STRLEN                                           ~10     !0
         19        MOD                                              ~11     ~10, 4
         20        SEND_VAL                                                 ~11
         21        DO_ICALL                                         $12     
         22        CONCAT                                           ~13     $9, $12
         23        ASSIGN                                                   !2, ~13
   34    24        INIT_FCALL                                               'base64_decode'
         25        SEND_VAR                                                 !2
         26        SEND_VAL                                                 <true>
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !1, $15
   35    29        TYPE_CHECK                                    4          !1
         30      > JMPZ                                                     ~17, ->35
   36    31    >   NEW                                              $18     'Exception'
         32        SEND_VAL_EX                                              'base64_decode%28%29+failed'
         33        DO_FCALL                                      0          
         34      > THROW                                         0          $18
   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:
161.13 ms | 1400 KiB | 23 Q