3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DependencyContainer { /** * * @var array */ private $dependencies; /** * * @param string $key * @param string $value */ public function __set($key, $value) { $this->setDependency($key, $value); } /** * * @param string $name * @return mixed */ public function __get($name) { return $this->getDependency($name); } /** * * @param string $dependency_name * @param mixed $implementation * @throws InvalidArgumentException */ public function setDependency($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 string */ 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])) return $this->dependencies[$dependency_name]($this); else return $this->dependencies[$dependency_name]; } public function getSingelton($lambda) { return function($container) use ($lambda) { static $object; if(is_null($object)) $object = $lambda($container); return $object; }; } } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v7fME
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fv7fME%3A72%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
filename:       /in/v7fME
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $container, !1 = $lambda, !2 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   73     2        BIND_STATIC                                              !2
   75     3        TYPE_CHECK                                    2          !2
          4      > JMPZ                                                     ~3, ->9
   76     5    >   INIT_DYNAMIC_CALL                                        !1
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !2, $4
   78     9    > > RETURN                                                   !2
   79    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fv7fME%3A72%240

Class DependencyContainer:
Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v7fME
function name:  __set
number of ops:  7
compiled vars:  !0 = $key, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        INIT_METHOD_CALL                                         'setDependency'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
   19     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/v7fME
function name:  __get
number of ops:  6
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   28     1        INIT_METHOD_CALL                                         'getDependency'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   29     5*     > RETURN                                                   null

End of function __get

Function setdependency:
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/v7fME
function name:  setDependency
number of ops:  16
compiled vars:  !0 = $dependency_name, !1 = $implementation
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   39     2        TYPE_CHECK                                   64  ~2      !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->12
   40     5    >   NEW                                              $4      'InvalidArgumentException'
   41     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
   44    12    >   FETCH_OBJ_W                                      $9      'dependencies'
         13        ASSIGN_DIM                                               $9, !0
         14        OP_DATA                                                  !1
   45    15      > RETURN                                                   null

End of function setdependency

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

End of function getdependency

Function getsingelton:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v7fME
function name:  getSingelton
number of ops:  5
compiled vars:  !0 = $lambda
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   RECV                                             !0      
   72     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fv7fME%3A72%240'
          2        BIND_LEXICAL                                             ~1, !0
   79     3      > RETURN                                                   ~1
   80     4*     > RETURN                                                   null

End of function getsingelton

End of class DependencyContainer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.75 ms | 1396 KiB | 15 Q