3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace App; class Container { private array $objects = []; public function __construct() { // Ключи в этом массиве - строковые ID объектов // Значения - функции, строящие нужный объект $this->objects = [ 'db' => fn() => new Db(), 'repository.user' => fn() => new UserRepository($this->get('db')), 'controller.user' => fn() => new UserController($this->get('repository.user')), ]; } public function has(string $id): bool { return isset($this->objects[$id]); } public function get(string $id): mixed { return $this->objects[$id](); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E > > RETURN                                                   1

Class App\Container:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   DECLARE_LAMBDA_FUNCTION                          ~1      [0]
          1        INIT_ARRAY                                       ~2      ~1, 'db'
   16     2        DECLARE_LAMBDA_FUNCTION                          ~3      [1]
          3        ADD_ARRAY_ELEMENT                                ~2      ~3, 'repository.user'
   17     4        DECLARE_LAMBDA_FUNCTION                          ~4      [2]
          5        ADD_ARRAY_ELEMENT                                ~2      ~4, 'controller.user'
   14     6        ASSIGN_OBJ                                               'objects'
   17     7        OP_DATA                                                  ~2
   19     8      > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  App\{closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                                              $0      'App%5CDb'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
          3*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  App\{closure}
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   NEW                                              $0      'App%5CUserRepository'
          1        FETCH_THIS                                       $1      
          2        INIT_METHOD_CALL                                         $1, 'get'
          3        SEND_VAL_EX                                              'db'
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7      > RETURN                                                   $0
          8*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  App\{closure}
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   NEW                                              $0      'App%5CUserController'
          1        FETCH_THIS                                       $1      
          2        INIT_METHOD_CALL                                         $1, 'get'
          3        SEND_VAL_EX                                              'repository.user'
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR_NO_REF_EX                                       $2
          6        DO_FCALL                                      0          
          7      > RETURN                                                   $0
          8*     > RETURN                                                   null

End of Dynamic Function 2

End of function __construct

Function has:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  has
number of ops:  7
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   23     1        FETCH_OBJ_IS                                     ~1      'objects'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   24     5*       VERIFY_RETURN_TYPE                                       
          6*     > RETURN                                                   null

End of function has

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oAk18
function name:  get
number of ops:  8
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        FETCH_OBJ_R                                      ~1      'objects'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3        INIT_DYNAMIC_CALL                                        ~2
          4        DO_FCALL                                      0  $3      
          5      > RETURN                                                   $3
   29     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function get

End of class App\Container.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.35 ms | 1000 KiB | 13 Q