3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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); for($i = 0 ; $i < count($rel_components) ; ++$i) { if ($path_components[$i] == $rel[$i]) array_shift($copy); else break; } return $copy; } var_dump(path_relative_to("/a/b/c", "/"));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MvORl
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'path_relative_to'
          2        SEND_VAL                                                 '%2Fa%2Fb%2Fc'
          3        SEND_VAL                                                 '%2F'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

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

End of function path_relative_to

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.68 ms | 1403 KiB | 26 Q