3v4l.org

run code in 300+ PHP versions simultaneously
<?php $path = 'phar://test.phar/a/b/./.././v/../file.txt'; $isUnixPath = ((strlen($path) === 0) || ($path[0] !== '/')); // Checks if path is relative. if ((strpos($path, ':') === false) && ($isUnixPath === true)) { $path = getcwd() . DIRECTORY_SEPARATOR . $path; } // Resolve path parts (single dot, double dot and double delimiters). $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen'); $absolutes = array(); foreach ($parts as $part) { if (('.' === $part) || ('' === $part)) { continue; } if ('..' === $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } $path = implode(DIRECTORY_SEPARATOR, $absolutes); // Resolve any symlinks. if ((file_exists($path) === true) && (linkinfo($path) > 0)) { $path = readlink($path); } if ($isUnixPath === false) { $path = '/' . $path; } echo $path;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 55
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 55
Branch analysis from position: 40
2 jumps found. (Code = 47) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 52
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 44
Branch analysis from position: 55
2 jumps found. (Code = 46) Position 1 = 66, Position 2 = 71
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 76
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 76
Branch analysis from position: 71
Branch analysis from position: 55
Branch analysis from position: 22
Branch analysis from position: 16
Branch analysis from position: 7
filename:       /in/WMtJi
function name:  (null)
number of ops:  82
compiled vars:  !0 = $path, !1 = $isUnixPath, !2 = $parts, !3 = $absolutes, !4 = $part
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'phar%3A%2F%2Ftest.phar%2Fa%2Fb%2F.%2F..%2F.%2Fv%2F..%2Ffile.txt'
    5     1        STRLEN                                           ~6      !0
          2        IS_IDENTICAL                                     ~7      ~6, 0
          3      > JMPNZ_EX                                         ~7      ~7, ->7
          4    >   FETCH_DIM_R                                      ~8      !0, 0
          5        IS_NOT_IDENTICAL                                 ~9      ~8, '%2F'
          6        BOOL                                             ~7      ~9
          7    >   ASSIGN                                                   !1, ~7
    8     8        INIT_FCALL                                               'strpos'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 '%3A'
         11        DO_ICALL                                         $11     
         12        TYPE_CHECK                                    4  ~12     $11
         13      > JMPZ_EX                                          ~12     ~12, ->16
         14    >   TYPE_CHECK                                    8  ~13     !1
         15        BOOL                                             ~12     ~13
         16    > > JMPZ                                                     ~12, ->22
    9    17    >   INIT_FCALL                                               'getcwd'
         18        DO_ICALL                                         $14     
         19        CONCAT                                           ~15     $14, '%2F'
         20        CONCAT                                           ~16     ~15, !0
         21        ASSIGN                                                   !0, ~16
   13    22    >   INIT_FCALL                                               'str_replace'
         23        SEND_VAL                                                 <array>
         24        SEND_VAL                                                 '%2F'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $18     
         27        ASSIGN                                                   !0, $18
   14    28        INIT_FCALL                                               'array_filter'
         29        INIT_FCALL                                               'explode'
         30        SEND_VAL                                                 '%2F'
         31        SEND_VAR                                                 !0
         32        DO_ICALL                                         $20     
         33        SEND_VAR                                                 $20
         34        SEND_VAL                                                 'strlen'
         35        DO_ICALL                                         $21     
         36        ASSIGN                                                   !2, $21
   15    37        ASSIGN                                                   !3, <array>
   16    38      > FE_RESET_R                                       $24     !2, ->55
         39    > > FE_FETCH_R                                               $24, !4, ->55
   17    40    >   IS_IDENTICAL                                     ~25     !4, '.'
         41      > JMPNZ_EX                                         ~25     ~25, ->44
         42    >   IS_IDENTICAL                                     ~26     !4, ''
         43        BOOL                                             ~25     ~26
         44    > > JMPZ                                                     ~25, ->46
   18    45    > > JMP                                                      ->39
   20    46    >   IS_IDENTICAL                                             !4, '..'
         47      > JMPZ                                                     ~27, ->52
   21    48    >   INIT_FCALL                                               'array_pop'
         49        SEND_REF                                                 !3
         50        DO_ICALL                                                 
         51      > JMP                                                      ->54
   23    52    >   ASSIGN_DIM                                               !3
         53        OP_DATA                                                  !4
   16    54    > > JMP                                                      ->39
         55    >   FE_FREE                                                  $24
   26    56        INIT_FCALL                                               'implode'
         57        SEND_VAL                                                 '%2F'
         58        SEND_VAR                                                 !3
         59        DO_ICALL                                         $30     
         60        ASSIGN                                                   !0, $30
   29    61        INIT_FCALL                                               'file_exists'
         62        SEND_VAR                                                 !0
         63        DO_ICALL                                         $32     
         64        TYPE_CHECK                                    8  ~33     $32
         65      > JMPZ_EX                                          ~33     ~33, ->71
         66    >   INIT_FCALL                                               'linkinfo'
         67        SEND_VAR                                                 !0
         68        DO_ICALL                                         $34     
         69        IS_SMALLER                                       ~35     0, $34
         70        BOOL                                             ~33     ~35
         71    > > JMPZ                                                     ~33, ->76
   30    72    >   INIT_FCALL                                               'readlink'
         73        SEND_VAR                                                 !0
         74        DO_ICALL                                         $36     
         75        ASSIGN                                                   !0, $36
   33    76    >   TYPE_CHECK                                    4          !1
         77      > JMPZ                                                     ~38, ->80
   34    78    >   CONCAT                                           ~39     '%2F', !0
         79        ASSIGN                                                   !0, ~39
   38    80    >   ECHO                                                     !0
         81      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.34 ms | 1408 KiB | 34 Q