3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Controller { public function __construct(B $b) { $this->b = $b; } } class B { public function __construct(C $c) { $this->c = $c; } } class C { public function __construct(Guzzle $guzzle) { $this->guzzle = $guzzle; } } class Guzzle { public function __construct() { } } $getReflectedConstructorParams = function($className) { return (new ReflectionClass($className))->getConstructor()->getParameters(); }; $className = 'Controller'; $graph = []; // I hate recursion, there's much better ways while (true) { $params = $getReflectedConstructorParams($className); // Guard clause if (!isset($params[0])) { // We'll have reached the Guzzle object here, the last one in the chain $prevObj = null; foreach ($graph as $obj) { // This will only happen once if ($prevObj === null) { $prevObj = new $obj; continue; } $prevObj = new $obj($prevObj); var_dump($prevObj); die; } var_dump($prevObj); break; } $className = $params[0]->getClass()->getName(); $graph[] = $className; } var_dump($graph);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 5
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 37
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 32
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 32
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 22
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
Branch analysis from position: 32
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 5
Branch analysis from position: 46
Branch analysis from position: 5
filename:       /in/UJktq
function name:  (null)
number of ops:  50
compiled vars:  !0 = $getReflectedConstructorParams, !1 = $className, !2 = $graph, !3 = $params, !4 = $prevObj, !5 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUJktq%3A8%240'
          1        ASSIGN                                                   !0, ~6
   12     2        ASSIGN                                                   !1, 'Controller'
   13     3        ASSIGN                                                   !2, <array>
   16     4      > JMP                                                      ->45
   18     5    >   INIT_DYNAMIC_CALL                                        !0
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $10     
          8        ASSIGN                                                   !3, $10
   21     9        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !3, 0
         10        BOOL_NOT                                         ~13     ~12
         11      > JMPZ                                                     ~13, ->37
   24    12    >   ASSIGN                                                   !4, null
   25    13      > FE_RESET_R                                       $15     !2, ->32
         14    > > FE_FETCH_R                                               $15, !5, ->32
   28    15    >   TYPE_CHECK                                    2          !4
         16      > JMPZ                                                     ~16, ->22
   30    17    >   FETCH_CLASS                                   0  $17     !5
         18        NEW                                              $18     $17
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !4, $18
   32    21      > JMP                                                      ->14
   35    22    >   FETCH_CLASS                                   0  $21     !5
         23        NEW                                              $22     $21
         24        SEND_VAR_EX                                              !4
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !4, $22
   36    27        INIT_FCALL                                               'var_dump'
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                                 
         30      > EXIT                                                     
   25    31*       JMP                                                      ->14
         32    >   FE_FREE                                                  $15
   39    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                                 
   41    36      > JMP                                                      ->46
   44    37    >   FETCH_DIM_R                                      ~27     !3, 0
         38        INIT_METHOD_CALL                                         ~27, 'getClass'
         39        DO_FCALL                                      0  $28     
         40        INIT_METHOD_CALL                                         $28, 'getName'
         41        DO_FCALL                                      0  $29     
         42        ASSIGN                                                   !1, $29
   45    43        ASSIGN_DIM                                               !2
         44        OP_DATA                                                  !1
   16    45    > > JMPNZ                                                    <true>, ->5
   49    46    >   INIT_FCALL                                               'var_dump'
         47        SEND_VAR                                                 !2
         48        DO_ICALL                                                 
         49      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FUJktq%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UJktq
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        NEW                                              $1      'ReflectionClass'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $1, 'getConstructor'
          5        DO_FCALL                                      0  $3      
          6        INIT_METHOD_CALL                                         $3, 'getParameters'
          7        DO_FCALL                                      0  $4      
          8      > RETURN                                                   $4
   10     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FUJktq%3A8%240

Class Controller:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UJktq
function name:  __construct
number of ops:  4
compiled vars:  !0 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'b'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function __construct

End of class Controller.

Class B:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UJktq
function name:  __construct
number of ops:  4
compiled vars:  !0 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'c'
          2        OP_DATA                                                  !0
          3      > RETURN                                                   null

End of function __construct

End of class B.

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

End of function __construct

End of class C.

Class Guzzle:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UJktq
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E > > RETURN                                                   null

End of function __construct

End of class Guzzle.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.18 ms | 1404 KiB | 15 Q