3v4l.org

run code in 300+ PHP versions simultaneously
<?php class CookieCodec { /** * All characters valid in a cookie according to https://tools.ietf.org/html/rfc6265 and we have additionally * removed % (used for escape sequences) and + (which, if not encoded, is interpreted as space in cookies by PHP, * but there's no equivalent built-in JS decoding function, so we escape it to make decoding equivalent in both * cases). */ private const COOKIE_CHARSET = '!#$&\'()*-./0123456789:<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~'; public static function encode($string) { $string = (string) $string; $output = ''; for ($i = 0, $m = \strlen($string); $i < $m; $i++) { $char = $string[$i]; if (\strpos(self::COOKIE_CHARSET, $char) === false) { $ord = \ord($char); $code = \strtoupper(\dechex($ord)); $output .= $ord > 15 ? "%$code" : "%0$code"; } else { $output .= $char; } } return $output; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gQKLF
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E > > RETURN                                                   1

Class CookieCodec:
Function encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 8
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 8
Branch analysis from position: 42
Branch analysis from position: 8
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 8
Branch analysis from position: 42
Branch analysis from position: 8
filename:       /in/gQKLF
function name:  encode
number of ops:  44
compiled vars:  !0 = $string, !1 = $output, !2 = $i, !3 = $m, !4 = $char, !5 = $ord, !6 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        CAST                                          6  ~7      !0
          2        ASSIGN                                                   !0, ~7
   14     3        ASSIGN                                                   !1, ''
   15     4        ASSIGN                                                   !2, 0
          5        STRLEN                                           ~11     !0
          6        ASSIGN                                                   !3, ~11
          7      > JMP                                                      ->40
   16     8    >   FETCH_DIM_R                                      ~13     !0, !2
          9        ASSIGN                                                   !4, ~13
   17    10        INIT_FCALL                                               'strpos'
         11        SEND_VAL                                                 '%21%23%24%26%27%28%29%2A-.%2F0123456789%3A%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E'
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $15     
         14        TYPE_CHECK                                    4          $15
         15      > JMPZ                                                     ~16, ->38
   18    16    >   INIT_FCALL                                               'ord'
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $17     
         19        ASSIGN                                                   !5, $17
   19    20        INIT_FCALL                                               'strtoupper'
         21        INIT_FCALL                                               'dechex'
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $19     
         24        SEND_VAR                                                 $19
         25        DO_ICALL                                         $20     
         26        ASSIGN                                                   !6, $20
   20    27        IS_SMALLER                                               15, !5
         28      > JMPZ                                                     ~22, ->33
         29    >   NOP                                                      
         30        FAST_CONCAT                                      ~23     '%25', !6
         31        QM_ASSIGN                                        ~24     ~23
         32      > JMP                                                      ->36
         33    >   NOP                                                      
         34        FAST_CONCAT                                      ~25     '%250', !6
         35        QM_ASSIGN                                        ~24     ~25
         36    >   ASSIGN_OP                                     8          !1, ~24
         37      > JMP                                                      ->39
   22    38    >   ASSIGN_OP                                     8          !1, !4
   15    39    >   PRE_INC                                                  !2
         40    >   IS_SMALLER                                               !2, !3
         41      > JMPNZ                                                    ~29, ->8
   25    42    > > RETURN                                                   !1
   26    43*     > RETURN                                                   null

End of function encode

End of class CookieCodec.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.1 ms | 1400 KiB | 21 Q