3v4l.org

run code in 300+ PHP versions simultaneously
<?php function concat_path_components($path_components) { $first_component = array_shift($path_components); if ($first_component == NULL) return ""; return array_reduce( $path_components, function ($path, $path_component) { return $path . DIRECTORY_SEPARATOR . $path_component; }, $first_component); } function path_components($path) { $components = array(); while ($path != "." && $path != "/") { array_unshift($components, basename($path)); $path = dirname($path); } if ($path == "/") array_unshift($components, "/"); return $components; } function path_relative_to($path, $rel) { $path_components = path_components($path); $copy = $path_components; $rel_components = path_components($rel); var_dump($path_components); var_dump($rel_components); for($i = 0 ; $i < count($rel_components) ; ++$i) { if ($path_components[$i] == $rel[$i]) array_shift($copy); else break; } var_dump($copy); echo $i . " " . count($rel_components) . PHP_EOL; if ($i == count($rel_components)) return concat_path_components($copy); else return NULL; } var_dump(path_relative_to("/a/b/c", "/a/b"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VXZct
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'path_relative_to'
          2        SEND_VAL                                                 '%2Fa%2Fb%2Fc'
          3        SEND_VAL                                                 '%2Fa%2Fb'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function concat_path_components:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VXZct
function name:  concat_path_components
number of ops:  16
compiled vars:  !0 = $path_components, !1 = $first_component
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'array_shift'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !1, $2
    7     5        IS_EQUAL                                                 !1, null
          6      > JMPZ                                                     ~4, ->8
    8     7    > > RETURN                                                   ''
   10     8    >   INIT_FCALL                                               'array_reduce'
   11     9        SEND_VAR                                                 !0
   12    10        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FVXZct%3A12%240'
   15    11        SEND_VAL                                                 ~5
   16    12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $6      
         14      > RETURN                                                   $6
   17    15*     > RETURN                                                   null

End of function concat_path_components

Function %00%7Bclosure%7D%2Fin%2FVXZct%3A12%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VXZct
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $path, !1 = $path_component
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        CONCAT                                           ~2      !0, '%2F'
          3        CONCAT                                           ~3      ~2, !1
          4      > RETURN                                                   ~3
   15     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FVXZct%3A12%240

Function path_components:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 3
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 3
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
Branch analysis from position: 18
Branch analysis from position: 18
filename:       /in/VXZct
function name:  path_components
number of ops:  27
compiled vars:  !0 = $path, !1 = $components
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   21     1        ASSIGN                                                   !1, <array>
   22     2      > JMP                                                      ->14
   24     3    >   INIT_FCALL                                               'array_unshift'
          4        SEND_REF                                                 !1
          5        INIT_FCALL                                               'basename'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        SEND_VAR                                                 $3
          9        DO_ICALL                                                 
   25    10        INIT_FCALL                                               'dirname'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $5      
         13        ASSIGN                                                   !0, $5
   22    14    >   IS_NOT_EQUAL                                     ~7      !0, '.'
         15      > JMPZ_EX                                          ~7      ~7, ->18
         16    >   IS_NOT_EQUAL                                     ~8      !0, '%2F'
         17        BOOL                                             ~7      ~8
         18    > > JMPNZ                                                    ~7, ->3
   28    19    >   IS_EQUAL                                                 !0, '%2F'
         20      > JMPZ                                                     ~9, ->25
   29    21    >   INIT_FCALL                                               'array_unshift'
         22        SEND_REF                                                 !1
         23        SEND_VAL                                                 '%2F'
         24        DO_ICALL                                                 
   31    25    > > RETURN                                                   !1
   32    26*     > RETURN                                                   null

End of function path_components

Function path_relative_to:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 19
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 48
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 19
Branch analysis from position: 32
Branch analysis from position: 19
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
filename:       /in/VXZct
function name:  path_relative_to
number of ops:  50
compiled vars:  !0 = $path, !1 = $rel, !2 = $path_components, !3 = $copy, !4 = $rel_components, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        INIT_FCALL                                               'path_components'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $6      
          5        ASSIGN                                                   !2, $6
   37     6        ASSIGN                                                   !3, !2
   38     7        INIT_FCALL                                               'path_components'
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !4, $9
   40    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
   41    14        INIT_FCALL                                               'var_dump'
         15        SEND_VAR                                                 !4
         16        DO_ICALL                                                 
   43    17        ASSIGN                                                   !5, 0
         18      > JMP                                                      ->29
   45    19    >   FETCH_DIM_R                                      ~14     !2, !5
         20        FETCH_DIM_R                                      ~15     !1, !5
         21        IS_EQUAL                                                 ~14, ~15
         22      > JMPZ                                                     ~16, ->27
   46    23    >   INIT_FCALL                                               'array_shift'
         24        SEND_REF                                                 !3
         25        DO_ICALL                                                 
         26      > JMP                                                      ->28
   48    27    > > JMP                                                      ->32
   43    28    >   PRE_INC                                                  !5
         29    >   COUNT                                            ~19     !4
         30        IS_SMALLER                                               !5, ~19
         31      > JMPNZ                                                    ~20, ->19
   51    32    >   INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                                 
   53    35        CONCAT                                           ~22     !5, '+'
         36        COUNT                                            ~23     !4
         37        CONCAT                                           ~24     ~22, ~23
         38        CONCAT                                           ~25     ~24, '%0A'
         39        ECHO                                                     ~25
   55    40        COUNT                                            ~26     !4
         41        IS_EQUAL                                                 !5, ~26
         42      > JMPZ                                                     ~27, ->48
   56    43    >   INIT_FCALL                                               'concat_path_components'
         44        SEND_VAR                                                 !3
         45        DO_FCALL                                      0  $28     
         46      > RETURN                                                   $28
         47*       JMP                                                      ->49
   58    48    > > RETURN                                                   null
   59    49*     > RETURN                                                   null

End of function path_relative_to

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.16 ms | 1411 KiB | 29 Q