3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AttemptingToRegisterServiceUsingBusyName extends Exception implements ContainerExceptionInterface{} class AttemptToObtainOrCreateUnregisteredService extends Exception implements NotFoundExceptionInterface{} class DIContainer implements ContainerInterface { private array $registered = []; private array $created = []; public function register(string $id, callable $factory): void { if ($this->has($id)) { throw new AttemptingToRegisterServiceUsingBusyName('Сервис с таким именем уже зарегистрирован.'); } $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 AttemptToObtainOrCreateUnregisteredService('Сервис с таким именем не зарегистрирован.'); } } public function has(string $id): bool { return isset($this->registered[$id]); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rcZVi
function name:  (null)
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'attemptingtoregisterserviceusingbusyname', 'exception'
    5     1        DECLARE_CLASS                                            'attempttoobtainorcreateunregisteredservice', 'exception'
    7     2        DECLARE_CLASS                                            'dicontainer'
   39     3      > RETURN                                                   1

Class AttemptingToRegisterServiceUsingBusyName: [no user functions]
Class AttemptToObtainOrCreateUnregisteredService: [no user functions]
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/rcZVi
function name:  register
number of ops:  14
compiled vars:  !0 = $id, !1 = $factory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        INIT_METHOD_CALL                                         'has'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > JMPZ                                                     $2, ->10
   16     6    >   NEW                                              $3      'AttemptingToRegisterServiceUsingBusyName'
          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
   19    10    >   FETCH_OBJ_W                                      $5      'registered'
         11        ASSIGN_DIM                                               $5, !0
         12        OP_DATA                                                  !1
   20    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/rcZVi
function name:  get
number of ops:  30
compiled vars:  !0 = $id, !1 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        FETCH_OBJ_R                                      ~2      'created'
          2        ARRAY_KEY_EXISTS                                         !0, ~2
          3      > JMPZ                                                     ~3, ->8
   25     4    >   FETCH_OBJ_R                                      ~4      'created'
          5        FETCH_DIM_R                                      ~5      ~4, !0
          6      > RETURN                                                   ~5
   24     7*       JMP                                                      ->28
   26     8    >   INIT_METHOD_CALL                                         'has'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $6      
         11      > JMPZ                                                     $6, ->24
   27    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
   28    19        FETCH_OBJ_W                                      $12     'created'
         20        ASSIGN_DIM                                               $12, !0
         21        OP_DATA                                                  !1
   29    22      > RETURN                                                   !1
   26    23*       JMP                                                      ->28
   31    24    >   NEW                                              $14     'AttemptToObtainOrCreateUnregisteredService'
         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
   33    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/rcZVi
function name:  has
number of ops:  7
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        FETCH_OBJ_IS                                     ~1      'registered'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        VERIFY_RETURN_TYPE                                       ~2
          4      > RETURN                                                   ~2
   38     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:
131.63 ms | 1000 KiB | 13 Q