3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Path { public $currentPath; private $array; function __construct( $path ) { $this->currentPath = $path; $this->array = array_slice( explode( "/", $path ), 1 ); } public function cd( $newPath ) { if ( $newPath == "" || $newPath == "." ) { return $this; } $change = explode( "/", $newPath ); foreach ( $change as $value ) { if ( $value == ".." ) { if ( count( $this->array ) > 0 ) { array_pop($this->array); } } elseif ( $value !== "" ) { array_push( $this->array, $value ); } } if ( count( $this->array ) > 0 ) { $this->currentPath = "/" + implode( "/", $this->array ); } else { $this->currentPath = "/"; } return $this; } } $path = new Path('/a/b/c/d'); echo $path->cd('../../x')->currentPath;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YduXP
function name:  (null)
number of ops:  10
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   NEW                                              $1      'Path'
          1        SEND_VAL_EX                                              '%2Fa%2Fb%2Fc%2Fd'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   37     4        INIT_METHOD_CALL                                         !0, 'cd'
          5        SEND_VAL_EX                                              '..%2F..%2Fx'
          6        DO_FCALL                                      0  $4      
          7        FETCH_OBJ_R                                      ~5      $4, 'currentPath'
          8        ECHO                                                     ~5
          9      > RETURN                                                   1

Class Path:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YduXP
function name:  __construct
number of ops:  14
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        ASSIGN_OBJ                                               'currentPath'
          2        OP_DATA                                                  !0
    8     3        INIT_FCALL                                               'array_slice'
          4        INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%2F'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $3      
          8        SEND_VAR                                                 $3
          9        SEND_VAL                                                 1
         10        DO_ICALL                                         $4      
         11        ASSIGN_OBJ                                               'array'
         12        OP_DATA                                                  $4
    9    13      > RETURN                                                   null

End of function __construct

Function cd:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 34
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 25
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 33
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 48
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
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: 34
Branch analysis from position: 5
filename:       /in/YduXP
function name:  cd
number of ops:  53
compiled vars:  !0 = $newPath, !1 = $change, !2 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        IS_EQUAL                                         ~3      !0, ''
          2      > JMPNZ_EX                                         ~3      ~3, ->5
          3    >   IS_EQUAL                                         ~4      !0, '.'
          4        BOOL                                             ~3      ~4
          5    > > JMPZ                                                     ~3, ->8
   13     6    >   FETCH_THIS                                       ~5      
          7      > RETURN                                                   ~5
   16     8    >   INIT_FCALL                                               'explode'
          9        SEND_VAL                                                 '%2F'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $6      
         12        ASSIGN                                                   !1, $6
   17    13      > FE_RESET_R                                       $8      !1, ->34
         14    > > FE_FETCH_R                                               $8, !2, ->34
   18    15    >   IS_EQUAL                                                 !2, '..'
         16      > JMPZ                                                     ~9, ->26
   19    17    >   FETCH_OBJ_R                                      ~10     'array'
         18        COUNT                                            ~11     ~10
         19        IS_SMALLER                                               0, ~11
         20      > JMPZ                                                     ~12, ->25
   20    21    >   INIT_FCALL                                               'array_pop'
         22        FETCH_OBJ_W                                      $13     'array'
         23        SEND_REF                                                 $13
         24        DO_ICALL                                                 
         25    > > JMP                                                      ->33
   22    26    >   IS_NOT_IDENTICAL                                         !2, ''
         27      > JMPZ                                                     ~15, ->33
   23    28    >   INIT_FCALL                                               'array_push'
         29        FETCH_OBJ_W                                      $16     'array'
         30        SEND_REF                                                 $16
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                                 
   17    33    > > JMP                                                      ->14
         34    >   FE_FREE                                                  $8
   27    35        FETCH_OBJ_R                                      ~18     'array'
         36        COUNT                                            ~19     ~18
         37        IS_SMALLER                                               0, ~19
         38      > JMPZ                                                     ~20, ->48
   28    39    >   INIT_FCALL                                               'implode'
         40        SEND_VAL                                                 '%2F'
         41        FETCH_OBJ_R                                      ~22     'array'
         42        SEND_VAL                                                 ~22
         43        DO_ICALL                                         $23     
         44        ADD                                              ~24     '%2F', $23
         45        ASSIGN_OBJ                                               'currentPath'
         46        OP_DATA                                                  ~24
         47      > JMP                                                      ->50
   30    48    >   ASSIGN_OBJ                                               'currentPath'
         49        OP_DATA                                                  '%2F'
   32    50    >   FETCH_THIS                                       ~26     
         51      > RETURN                                                   ~26
   33    52*     > RETURN                                                   null

End of function cd

End of class Path.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.78 ms | 1404 KiB | 23 Q