3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = '~/test/../test2/test3/../file.php'; // Fake home setting. putenv( 'HOME=/Users/alain' ); function get_home_directory() { // Unix. $home = getenv( 'HOME' ); if ( ! empty( $home ) ) { return rtrim( $home, '/' ); } // Windows. if ( ! empty( $_SERVER['HOMEDRIVE'] ) && ! empty( $_SERVER['HOMEPATH'] ) ) { $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH']; return rtrim( $home, '\\/' ); } return '~'; } function get_normalized_path($path) { return array_reduce(explode('/', $path), function( $a = '/', $b ) { switch ( $b ) { case '': case '.': return $a; case '..': return dirname( $a ); case '~': return get_home_directory(); default: return preg_replace("/\/+/", "/", "$a/$b"); } } ); } echo $test . PHP_EOL; echo get_normalized_path( $test ) . PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9Ga8c
function name:  (null)
number of ops:  12
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%7E%2Ftest%2F..%2Ftest2%2Ftest3%2F..%2Ffile.php'
    4     1        INIT_FCALL                                               'putenv'
          2        SEND_VAL                                                 'HOME%3D%2FUsers%2Falain'
          3        DO_ICALL                                                 
   38     4        CONCAT                                           ~3      !0, '%0A'
          5        ECHO                                                     ~3
   39     6        INIT_FCALL                                               'get_normalized_path'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $4      
          9        CONCAT                                           ~5      $4, '%0A'
         10        ECHO                                                     ~5
         11      > RETURN                                                   1

Function get_home_directory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 32
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/9Ga8c
function name:  get_home_directory
number of ops:  34
compiled vars:  !0 = $home
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'getenv'
          1        SEND_VAL                                                 'HOME'
          2        DO_ICALL                                         $1      
          3        ASSIGN                                                   !0, $1
    9     4        ISSET_ISEMPTY_CV                                 ~3      !0
          5        BOOL_NOT                                         ~4      ~3
          6      > JMPZ                                                     ~4, ->12
   10     7    >   INIT_FCALL                                               'rtrim'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 '%2F'
         10        DO_ICALL                                         $5      
         11      > RETURN                                                   $5
   14    12    >   FETCH_IS                                         ~6      '_SERVER'
         13        ISSET_ISEMPTY_DIM_OBJ                         1  ~7      ~6, 'HOMEDRIVE'
         14        BOOL_NOT                                         ~8      ~7
         15      > JMPZ_EX                                          ~8      ~8, ->20
         16    >   FETCH_IS                                         ~9      '_SERVER'
         17        ISSET_ISEMPTY_DIM_OBJ                         1  ~10     ~9, 'HOMEPATH'
         18        BOOL_NOT                                         ~11     ~10
         19        BOOL                                             ~8      ~11
         20    > > JMPZ                                                     ~8, ->32
   15    21    >   FETCH_R                      global              ~12     '_SERVER'
         22        FETCH_DIM_R                                      ~13     ~12, 'HOMEDRIVE'
         23        FETCH_R                      global              ~14     '_SERVER'
         24        FETCH_DIM_R                                      ~15     ~14, 'HOMEPATH'
         25        CONCAT                                           ~16     ~13, ~15
         26        ASSIGN                                                   !0, ~16
   16    27        INIT_FCALL                                               'rtrim'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 '%5C%2F'
         30        DO_ICALL                                         $18     
         31      > RETURN                                                   $18
   19    32    > > RETURN                                                   '%7E'
   20    33*     > RETURN                                                   null

End of function get_home_directory

Function get_normalized_path:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9Ga8c
function name:  get_normalized_path
number of ops:  12
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        INIT_FCALL                                               'array_reduce'
          2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%2F'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        SEND_VAR                                                 $1
          7        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
   35     8        SEND_VAL                                                 ~2
   23     9        DO_ICALL                                         $3      
   35    10      > RETURN                                                   $3
   36    11*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
6 jumps found. (Code = 188) Position 1 = 12, Position 2 = 12, Position 3 = 13, Position 4 = 17, Position 5 = 20, Position 6 = 3
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 17
Branch analysis from position: 13
Branch analysis from position: 12
Branch analysis from position: 12
filename:       /in/9Ga8c
function name:  {closure}
number of ops:  30
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2      > SWITCH_STRING                                            !1, [ '':->12, '.':->12, '..':->13, '%7E':->17, ], ->20
   25     3    >   IS_EQUAL                                                 !1, ''
          4      > JMPNZ                                                    ~2, ->12
   26     5    >   IS_EQUAL                                                 !1, '.'
          6      > JMPNZ                                                    ~2, ->12
   28     7    >   IS_EQUAL                                                 !1, '..'
          8      > JMPNZ                                                    ~2, ->13
   30     9    >   IS_EQUAL                                                 !1, '%7E'
         10      > JMPNZ                                                    ~2, ->17
         11    > > JMP                                                      ->20
   27    12    > > RETURN                                                   !0
   29    13    >   INIT_FCALL                                               'dirname'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $3      
         16      > RETURN                                                   $3
   31    17    >   INIT_FCALL                                               'get_home_directory'
         18        DO_FCALL                                      0  $4      
         19      > RETURN                                                   $4
   33    20    >   INIT_FCALL                                               'preg_replace'
         21        SEND_VAL                                                 '%2F%5C%2F%2B%2F'
         22        SEND_VAL                                                 '%2F'
         23        ROPE_INIT                                     3  ~6      !0
         24        ROPE_ADD                                      1  ~6      ~6, '%2F'
         25        ROPE_END                                      2  ~5      ~6, !1
         26        SEND_VAL                                                 ~5
         27        DO_ICALL                                         $8      
         28      > RETURN                                                   $8
   35    29*     > RETURN                                                   null

End of Dynamic Function 0

End of function get_normalized_path

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.78 ms | 1454 KiB | 22 Q