3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Path { public $currentPath; private $array; function __construct($path) { $this->currentPath = $path; $array = explode("/", $path); } public function cd($newPath) { $change = explode("/", $newPath); foreach ($change as $value) { if ($value == "..") { if (count($array) > 0) { array_pop($array); } } else { array_push($array, $value); } } $currentPath = implode("/", $array); } } $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/GLfKA
function name:  (null)
number of ops:  10
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   NEW                                              $1      'Path'
          1        SEND_VAL_EX                                              '%2Fa%2Fb%2Fc%2Fd'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   28     4        INIT_METHOD_CALL                                         !0, 'cd'
          5        SEND_VAL_EX                                              '..%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/GLfKA
function name:  __construct
number of ops:  9
compiled vars:  !0 = $path, !1 = $array
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                                               'explode'
          4        SEND_VAL                                                 '%2F'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
    9     8      > RETURN                                                   null

End of function __construct

Function cd:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/GLfKA
function name:  cd
number of ops:  29
compiled vars:  !0 = $newPath, !1 = $change, !2 = $value, !3 = $array, !4 = $currentPath
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   12     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !1, $5
   13     6      > FE_RESET_R                                       $7      !1, ->22
          7    > > FE_FETCH_R                                               $7, !2, ->22
   14     8    >   IS_EQUAL                                                 !2, '..'
          9      > JMPZ                                                     ~8, ->17
   15    10    >   COUNT                                            ~9      !3
         11        IS_SMALLER                                               0, ~9
         12      > JMPZ                                                     ~10, ->16
   16    13    >   INIT_FCALL                                               'array_pop'
         14        SEND_REF                                                 !3
         15        DO_ICALL                                                 
         16    > > JMP                                                      ->21
   19    17    >   INIT_FCALL                                               'array_push'
         18        SEND_REF                                                 !3
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                                 
   13    21    > > JMP                                                      ->7
         22    >   FE_FREE                                                  $7
   23    23        INIT_FCALL                                               'implode'
         24        SEND_VAL                                                 '%2F'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $13     
         27        ASSIGN                                                   !4, $13
   24    28      > RETURN                                                   null

End of function cd

End of class Path.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.19 ms | 1400 KiB | 21 Q