3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { public int $number = 5; } class DIContainerException extends Exception{} interface ContainerInterface { public function get(string $id): mixed; public function has(string $id): bool; } class DIContainer implements ContainerInterface { private array $registered = []; private array $created = []; public function register(string $id, callable $factory): void { if ($this->has($id)) { throw new DIContainerException('Сервис с таким именем уже зарегистрирован.'); } $this->registered[$id] = $factory; } public function get(string $id): mixed { if (array_key_exists($id, $this->created)) { return $this->created[$id]; } elseif ($this->has($id)) { $object = call_user_func($this->registered[$id], $this); $this->created[$id] = $object; return $object; } else { throw new DIContainerException('Сервис с таким именем не зарегистрирован.'); } } public function has(string $id): bool { return isset($this->registered[$id]); } } $container = new DIContainer(); $container->register('Test', function(DIContainer $container) { return new Test(); }); var_dump($container->get('Test'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DvVbH
function name:  (null)
number of ops:  16
compiled vars:  !0 = $container
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_CLASS                                            'dicontainer'
   51     1        NEW                                              $1      'DIContainer'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   52     4        INIT_METHOD_CALL                                         !0, 'register'
          5        SEND_VAL_EX                                              'Test'
          6        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
   54     7        SEND_VAL_EX                                              ~4
   52     8        DO_FCALL                                      0          
   55     9        INIT_FCALL                                               'var_dump'
         10        INIT_METHOD_CALL                                         !0, 'get'
         11        SEND_VAL_EX                                              'Test'
         12        DO_FCALL                                      0  $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
         15      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DvVbH
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $container
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
   53     1        NEW                                              $1      'Test'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   $1
   54     4*     > RETURN                                                   null

End of Dynamic Function 0

Class Test: [no user functions]
Class DIContainerException: [no user functions]
Class ContainerInterface:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DvVbH
function name:  get
number of ops:  3
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        VERIFY_RETURN_TYPE                                       
          2      > RETURN                                                   null

End of function get

Function has:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DvVbH
function name:  has
number of ops:  3
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        VERIFY_RETURN_TYPE                                       
          2      > RETURN                                                   null

End of function has

End of class ContainerInterface.

Class DIContainer:
Function register:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DvVbH
function name:  register
number of ops:  14
compiled vars:  !0 = $id, !1 = $factory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        INIT_METHOD_CALL                                         'has'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > JMPZ                                                     $2, ->10
   26     6    >   NEW                                              $3      'DIContainerException'
          7        SEND_VAL_EX                                              '%D0%A1%D0%B5%D1%80%D0%B2%D0%B8%D1%81+%D1%81+%D1%82%D0%B0%D0%BA%D0%B8%D0%BC+%D0%B8%D0%BC%D0%B5%D0%BD%D0%B5%D0%BC+%D1%83%D0%B6%D0%B5+%D0%B7%D0%B0%D1%80%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD.'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $3
   29    10    >   FETCH_OBJ_W                                      $5      'registered'
         11        ASSIGN_DIM                                               $5, !0
         12        OP_DATA                                                  !1
   30    13      > RETURN                                                   null

End of function register

Function get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 108) Position 1 = -2
filename:       /in/DvVbH
function name:  get
number of ops:  30
compiled vars:  !0 = $id, !1 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   34     1        FETCH_OBJ_R                                      ~2      'created'
          2        ARRAY_KEY_EXISTS                                         !0, ~2
          3      > JMPZ                                                     ~3, ->8
   35     4    >   FETCH_OBJ_R                                      ~4      'created'
          5        FETCH_DIM_R                                      ~5      ~4, !0
          6      > RETURN                                                   ~5
   34     7*       JMP                                                      ->28
   36     8    >   INIT_METHOD_CALL                                         'has'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $6      
         11      > JMPZ                                                     $6, ->24
   37    12    >   FETCH_OBJ_R                                      ~7      'registered'
         13        FETCH_DIM_R                                      ~8      ~7, !0
         14        INIT_USER_CALL                                1          'call_user_func', ~8
         15        FETCH_THIS                                       ~9      
         16        SEND_USER                                                ~9
         17        DO_FCALL                                      0  $10     
         18        ASSIGN                                                   !1, $10
   38    19        FETCH_OBJ_W                                      $12     'created'
         20        ASSIGN_DIM                                               $12, !0
         21        OP_DATA                                                  !1
   39    22      > RETURN                                                   !1
   36    23*       JMP                                                      ->28
   41    24    >   NEW                                              $14     'DIContainerException'
         25        SEND_VAL_EX                                              '%D0%A1%D0%B5%D1%80%D0%B2%D0%B8%D1%81+%D1%81+%D1%82%D0%B0%D0%BA%D0%B8%D0%BC+%D0%B8%D0%BC%D0%B5%D0%BD%D0%B5%D0%BC+%D0%BD%D0%B5+%D0%B7%D0%B0%D1%80%D0%B5%D0%B3%D0%B8%D1%81%D1%82%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD.'
         26        DO_FCALL                                      0          
         27      > THROW                                         0          $14
   43    28*       VERIFY_RETURN_TYPE                                       
         29*     > RETURN                                                   null

End of function get

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

End of function has

End of class DIContainer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.46 ms | 1006 KiB | 14 Q