3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Graph{ private $v; private $adjList; public function __construct($vertices){ $this->v=$vertices; $this->initAdjList(); } //@suppressWarnings("unchecked") private function initAdjList(){ $this->adjList = array($this->v); for($i=0; $i<$this->v;$i++){ $this->adjList[$i]=array(); } } public function addEdge($u, $v){ array_push($this->adjList[$u],$v); } public function printAllPaths($s, $d){ $isVisted=array(); $isVisted=array_fill(0,$this->v,false); $pathList=array(); array_push($pathList,$s); $this->printAllPathsUtil($s, $d, $isVisted,$pathList); } private function printAllPathsUtil($u,$d,$isVisted,$localPathList){ $isVisted[intval($u)]=true; if(intval($u)==intval($d)){ // echo $localPathList; print_r($localPathList); } foreach ($this->adjList as $i){ if(!$isVisted[intval($i)]){ array_push($localPathList,$i); $this->printAllPathsUtil($i, $d, $isVisted, $localPathList); array_splice($localPathList,intval($i),1); } } $isVisted[intval($u)]=false; } } $g=new Graph(5); $g->addEdge(0,1); $g->addEdge(0,2); $g->addEdge(0,3); $g->addEdge(2,0); $g->addEdge(2,1); $g->addEdge(1,3); $g->addEdge(3,1); $g->addEdge(3,2); $g->addEdge(4,3); $g->addEdge(3,4); $s=0; $d=4; $g->printAllPaths($s,$d);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tS0ge
function name:  (null)
number of ops:  51
compiled vars:  !0 = $g, !1 = $s, !2 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $3      'Graph'
          1        SEND_VAL_EX                                              5
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $3
   52     4        INIT_METHOD_CALL                                         !0, 'addEdge'
          5        SEND_VAL_EX                                              0
          6        SEND_VAL_EX                                              1
          7        DO_FCALL                                      0          
   53     8        INIT_METHOD_CALL                                         !0, 'addEdge'
          9        SEND_VAL_EX                                              0
         10        SEND_VAL_EX                                              2
         11        DO_FCALL                                      0          
   54    12        INIT_METHOD_CALL                                         !0, 'addEdge'
         13        SEND_VAL_EX                                              0
         14        SEND_VAL_EX                                              3
         15        DO_FCALL                                      0          
   55    16        INIT_METHOD_CALL                                         !0, 'addEdge'
         17        SEND_VAL_EX                                              2
         18        SEND_VAL_EX                                              0
         19        DO_FCALL                                      0          
   56    20        INIT_METHOD_CALL                                         !0, 'addEdge'
         21        SEND_VAL_EX                                              2
         22        SEND_VAL_EX                                              1
         23        DO_FCALL                                      0          
   57    24        INIT_METHOD_CALL                                         !0, 'addEdge'
         25        SEND_VAL_EX                                              1
         26        SEND_VAL_EX                                              3
         27        DO_FCALL                                      0          
   58    28        INIT_METHOD_CALL                                         !0, 'addEdge'
         29        SEND_VAL_EX                                              3
         30        SEND_VAL_EX                                              1
         31        DO_FCALL                                      0          
   59    32        INIT_METHOD_CALL                                         !0, 'addEdge'
         33        SEND_VAL_EX                                              3
         34        SEND_VAL_EX                                              2
         35        DO_FCALL                                      0          
   60    36        INIT_METHOD_CALL                                         !0, 'addEdge'
         37        SEND_VAL_EX                                              4
         38        SEND_VAL_EX                                              3
         39        DO_FCALL                                      0          
   61    40        INIT_METHOD_CALL                                         !0, 'addEdge'
         41        SEND_VAL_EX                                              3
         42        SEND_VAL_EX                                              4
         43        DO_FCALL                                      0          
   62    44        ASSIGN                                                   !1, 0
   63    45        ASSIGN                                                   !2, 4
   64    46        INIT_METHOD_CALL                                         !0, 'printAllPaths'
         47        SEND_VAR_EX                                              !1
         48        SEND_VAR_EX                                              !2
         49        DO_FCALL                                      0          
         50      > RETURN                                                   1

Class Graph:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tS0ge
function name:  __construct
number of ops:  6
compiled vars:  !0 = $vertices
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        ASSIGN_OBJ                                               'v'
          2        OP_DATA                                                  !0
    9     3        INIT_METHOD_CALL                                         'initAdjList'
          4        DO_FCALL                                      0          
   10     5      > RETURN                                                   null

End of function __construct

Function initadjlist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 6
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 6
Branch analysis from position: 13
Branch analysis from position: 6
filename:       /in/tS0ge
function name:  initAdjList
number of ops:  14
compiled vars:  !0 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~2      'v'
          1        INIT_ARRAY                                       ~3      ~2
          2        ASSIGN_OBJ                                               'adjList'
          3        OP_DATA                                                  ~3
   15     4        ASSIGN                                                   !0, 0
          5      > JMP                                                      ->10
   16     6    >   FETCH_OBJ_W                                      $5      'adjList'
          7        ASSIGN_DIM                                               $5, !0
          8        OP_DATA                                                  <array>
   15     9        PRE_INC                                                  !0
         10    >   FETCH_OBJ_R                                      ~8      'v'
         11        IS_SMALLER                                               !0, ~8
         12      > JMPNZ                                                    ~9, ->6
   18    13    > > RETURN                                                   null

End of function initadjlist

Function addedge:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tS0ge
function name:  addEdge
number of ops:  9
compiled vars:  !0 = $u, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        INIT_FCALL                                               'array_push'
          3        FETCH_OBJ_W                                      $2      'adjList'
          4        FETCH_DIM_W                                      $3      $2, !0
          5        SEND_REF                                                 $3
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   22     8      > RETURN                                                   null

End of function addedge

Function printallpaths:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tS0ge
function name:  printAllPaths
number of ops:  22
compiled vars:  !0 = $s, !1 = $d, !2 = $isVisted, !3 = $pathList
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        ASSIGN                                                   !2, <array>
   26     3        INIT_FCALL                                               'array_fill'
          4        SEND_VAL                                                 0
          5        FETCH_OBJ_R                                      ~5      'v'
          6        SEND_VAL                                                 ~5
          7        SEND_VAL                                                 <false>
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !2, $6
   27    10        ASSIGN                                                   !3, <array>
   28    11        INIT_FCALL                                               'array_push'
         12        SEND_REF                                                 !3
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
   29    15        INIT_METHOD_CALL                                         'printAllPathsUtil'
         16        SEND_VAR_EX                                              !0
         17        SEND_VAR_EX                                              !1
         18        SEND_VAR_EX                                              !2
         19        SEND_VAR_EX                                              !3
         20        DO_FCALL                                      0          
   30    21      > RETURN                                                   null

End of function printallpaths

Function printallpathsutil:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 38
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 37
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 37
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 14
filename:       /in/tS0ge
function name:  printAllPathsUtil
number of ops:  43
compiled vars:  !0 = $u, !1 = $d, !2 = $isVisted, !3 = $localPathList, !4 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   33     4        CAST                                          4  ~5      !0
          5        ASSIGN_DIM                                               !2, ~5
          6        OP_DATA                                                  <true>
   35     7        CAST                                          4  ~7      !0
          8        CAST                                          4  ~8      !1
          9        IS_EQUAL                                                 ~7, ~8
         10      > JMPZ                                                     ~9, ->14
   37    11    >   INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                                 
   40    14    >   FETCH_OBJ_R                                      ~11     'adjList'
         15      > FE_RESET_R                                       $12     ~11, ->38
         16    > > FE_FETCH_R                                               $12, !4, ->38
   41    17    >   CAST                                          4  ~13     !4
         18        FETCH_DIM_R                                      ~14     !2, ~13
         19        BOOL_NOT                                         ~15     ~14
         20      > JMPZ                                                     ~15, ->37
   42    21    >   INIT_FCALL                                               'array_push'
         22        SEND_REF                                                 !3
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                                 
   43    25        INIT_METHOD_CALL                                         'printAllPathsUtil'
         26        SEND_VAR                                                 !4
         27        SEND_VAR                                                 !1
         28        SEND_VAR                                                 !2
         29        SEND_VAR                                                 !3
         30        DO_FCALL                                      0          
   44    31        INIT_FCALL                                               'array_splice'
         32        SEND_REF                                                 !3
         33        CAST                                          4  ~18     !4
         34        SEND_VAL                                                 ~18
         35        SEND_VAL                                                 1
         36        DO_ICALL                                                 
   40    37    > > JMP                                                      ->16
         38    >   FE_FREE                                                  $12
   47    39        CAST                                          4  ~20     !0
         40        ASSIGN_DIM                                               !2, ~20
         41        OP_DATA                                                  <false>
   48    42      > RETURN                                                   null

End of function printallpathsutil

End of class Graph.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.99 ms | 1408 KiB | 21 Q