3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DependencyContainer { /** @var array */ protected $dependencies; /** * * @param string $key * @param string $value */ public function __set($key, $value) { $this->addDependency($key, $value); } /** * * @param string $name * @return mixed */ public function __get($name) { return $this->getDependency($name); } /** * * @param string $dependency_name * @param string|callable $implementation * @throws InvalidArgumentException */ public function addDependency($dependency_name, $implementation) { if(!is_string($dependency_name)) throw new InvalidArgumentException( '$dependency_name must be a string! '.gettype($dependency_name).' given!' ); $this->dependencies[$dependency_name] = $implementation; } /** * * @param string $dependency_name * @throws InvalidArgumentException Wird geworfen wenn der erste Parameter kein String ist. * @throws OutOfRangeException Wird geworfen wenn für die Dependency keine Implementierung gesetzt wurde. * @return mixed */ public function getDependency($dependency_name) { if(!is_string($dependency_name)) throw new InvalidArgumentException( '$dependency_name must be a string! '.gettype($dependency_name).' given!' ); if(!isset($this->dependencies[$dependency_name])) throw new OutOfRangeException('No dependency set for '.$dependency_name.'!'); if(is_callable($this->dependencies[$dependency_name])) { $function = $this->dependencies[$dependency_name]; return $function($this); } else return new $this->dependencies[$dependency_name](); } public function hasDependency($dependency_name) { return isset($this->dependencies[$dependency_name]); } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAVZl
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E > > RETURN                                                   1

Class DependencyContainer:
Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAVZl
function name:  __set
number of ops:  7
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        INIT_METHOD_CALL                                         'addDependency'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   16     6      > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAVZl
function name:  __get
number of ops:  6
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        INIT_METHOD_CALL                                         'getDependency'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   26     5*     > RETURN                                                   null

End of function __get

Function adddependency:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAVZl
function name:  addDependency
number of ops:  16
compiled vars:  !0 = $dependency_name, !1 = $implementation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        TYPE_CHECK                                   64  ~2      !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->12
   37     5    >   NEW                                              $4      'InvalidArgumentException'
   38     6        GET_TYPE                                         ~5      !0
          7        CONCAT                                           ~6      '%24dependency_name+must+be+a+string%21+', ~5
          8        CONCAT                                           ~7      ~6, '+given%21'
          9        SEND_VAL_EX                                              ~7
         10        DO_FCALL                                      0          
         11      > THROW                                         0          $4
   41    12    >   FETCH_OBJ_W                                      $9      'dependencies'
         13        ASSIGN_DIM                                               $9, !0
         14        OP_DATA                                                  !1
   42    15      > RETURN                                                   null

End of function adddependency

Function getdependency:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 36
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAVZl
function name:  getDependency
number of ops:  43
compiled vars:  !0 = $dependency_name, !1 = $function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
   53     1        TYPE_CHECK                                   64  ~2      !0
          2        BOOL_NOT                                         ~3      ~2
          3      > JMPZ                                                     ~3, ->11
   54     4    >   NEW                                              $4      'InvalidArgumentException'
   55     5        GET_TYPE                                         ~5      !0
          6        CONCAT                                           ~6      '%24dependency_name+must+be+a+string%21+', ~5
          7        CONCAT                                           ~7      ~6, '+given%21'
          8        SEND_VAL_EX                                              ~7
          9        DO_FCALL                                      0          
         10      > THROW                                         0          $4
   58    11    >   FETCH_OBJ_IS                                     ~9      'dependencies'
         12        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     ~9, !0
         13        BOOL_NOT                                         ~11     ~10
         14      > JMPZ                                                     ~11, ->21
   59    15    >   NEW                                              $12     'OutOfRangeException'
         16        CONCAT                                           ~13     'No+dependency+set+for+', !0
         17        CONCAT                                           ~14     ~13, '%21'
         18        SEND_VAL_EX                                              ~14
         19        DO_FCALL                                      0          
         20      > THROW                                         0          $12
   61    21    >   INIT_FCALL                                               'is_callable'
         22        FETCH_OBJ_R                                      ~16     'dependencies'
         23        FETCH_DIM_R                                      ~17     ~16, !0
         24        SEND_VAL                                                 ~17
         25        DO_ICALL                                         $18     
         26      > JMPZ                                                     $18, ->36
   63    27    >   FETCH_OBJ_R                                      ~19     'dependencies'
         28        FETCH_DIM_R                                      ~20     ~19, !0
         29        ASSIGN                                                   !1, ~20
   64    30        INIT_DYNAMIC_CALL                                        !1
         31        FETCH_THIS                                       $22     
         32        SEND_VAR_EX                                              $22
         33        DO_FCALL                                      0  $23     
         34      > RETURN                                                   $23
         35*       JMP                                                      ->42
   67    36    >   FETCH_OBJ_R                                      ~24     'dependencies'
         37        FETCH_DIM_R                                      ~25     ~24, !0
         38        FETCH_CLASS                                   0  $26     ~25
         39        NEW                                              $27     $26
         40        DO_FCALL                                      0          
         41      > RETURN                                                   $27
   68    42*     > RETURN                                                   null

End of function getdependency

Function hasdependency:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UAVZl
function name:  hasDependency
number of ops:  5
compiled vars:  !0 = $dependency_name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   72     1        FETCH_OBJ_IS                                     ~1      'dependencies'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   73     4*     > RETURN                                                   null

End of function hasdependency

End of class DependencyContainer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.28 ms | 1404 KiB | 15 Q