3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Request { public function __construct() { echo 'Request created'; } } class DI { protected $shared = []; protected $definitions = []; public function __construct() {} public function set($name, $definition, $shared = false) { if($shared) { if(isset($shared[$name])) { throw new Exception("Definition '$name' is already set. Use DI::remove('$name') to remove it."); } $this->shared[$name] = $definition; } else { if(isset($definitions[$name])) { throw new Exception("Definition '$name' is already set. Use DI::remove('$name') to remove it."); } $this->definitions[$name] = $definition; } } public function getRaw($name) { if(!isset($this->definitions[$name])) { throw new Exception("Definition '$name' is not set. Use DI::set('$name', <definition>, <shared>) to set it."); } return $this->definitions[$name]; } public function get($name) { $definition = $this->getRaw($name); return $definition(); } } $di = new DI(); //Using an anonymous function $di->set('request', function(){ return new Request(); }); var_dump($di->get('request'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  (null)
number of ops:  15
compiled vars:  !0 = $di
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $1      'DI'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   46     3        INIT_METHOD_CALL                                         !0, 'set'
          4        SEND_VAL_EX                                              'request'
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FFo6Gu%3A46%240'
   48     6        SEND_VAL_EX                                              ~4
          7        DO_FCALL                                      0          
   50     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !0, 'get'
         10        SEND_VAL_EX                                              'request'
         11        DO_FCALL                                      0  $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FFo6Gu%3A46%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   NEW                                              $0      'Request'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   48     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FFo6Gu%3A46%240

Class Request:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  __construct
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ECHO                                                     'Request+created'
    6     1      > RETURN                                                   null

End of function __construct

End of class Request.

Class DI:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E > > RETURN                                                   null

End of function __construct

Function set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 30
Branch analysis from position: 21
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  set
number of ops:  34
compiled vars:  !0 = $name, !1 = $definition, !2 = $shared, !3 = $definitions
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   16     3      > JMPZ                                                     !2, ->19
   17     4    >   ISSET_ISEMPTY_DIM_OBJ                         0          !2, !0
          5      > JMPZ                                                     ~4, ->15
   18     6    >   NEW                                              $5      'Exception'
          7        ROPE_INIT                                     5  ~7      'Definition+%27'
          8        ROPE_ADD                                      1  ~7      ~7, !0
          9        ROPE_ADD                                      2  ~7      ~7, '%27+is+already+set.+Use+DI%3A%3Aremove%28%27'
         10        ROPE_ADD                                      3  ~7      ~7, !0
         11        ROPE_END                                      4  ~6      ~7, '%27%29+to+remove+it.'
         12        SEND_VAL_EX                                              ~6
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $5
   20    15    >   FETCH_OBJ_W                                      $11     'shared'
         16        ASSIGN_DIM                                               $11, !0
         17        OP_DATA                                                  !1
         18      > JMP                                                      ->33
   22    19    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, !0
         20      > JMPZ                                                     ~13, ->30
   23    21    >   NEW                                              $14     'Exception'
         22        ROPE_INIT                                     5  ~16     'Definition+%27'
         23        ROPE_ADD                                      1  ~16     ~16, !0
         24        ROPE_ADD                                      2  ~16     ~16, '%27+is+already+set.+Use+DI%3A%3Aremove%28%27'
         25        ROPE_ADD                                      3  ~16     ~16, !0
         26        ROPE_END                                      4  ~15     ~16, '%27%29+to+remove+it.'
         27        SEND_VAL_EX                                              ~15
         28        DO_FCALL                                      0          
         29      > THROW                                         0          $14
   25    30    >   FETCH_OBJ_W                                      $20     'definitions'
         31        ASSIGN_DIM                                               $20, !0
         32        OP_DATA                                                  !1
   27    33    > > RETURN                                                   null

End of function set

Function getraw:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  getRaw
number of ops:  18
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        FETCH_OBJ_IS                                     ~1      'definitions'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3        BOOL_NOT                                         ~3      ~2
          4      > JMPZ                                                     ~3, ->14
   31     5    >   NEW                                              $4      'Exception'
          6        ROPE_INIT                                     5  ~6      'Definition+%27'
          7        ROPE_ADD                                      1  ~6      ~6, !0
          8        ROPE_ADD                                      2  ~6      ~6, '%27+is+not+set.+Use+DI%3A%3Aset%28%27'
          9        ROPE_ADD                                      3  ~6      ~6, !0
         10        ROPE_END                                      4  ~5      ~6, '%27%2C+%3Cdefinition%3E%2C+%3Cshared%3E%29+to+set+it.'
         11        SEND_VAL_EX                                              ~5
         12        DO_FCALL                                      0          
         13      > THROW                                         0          $4
   34    14    >   FETCH_OBJ_R                                      ~10     'definitions'
         15        FETCH_DIM_R                                      ~11     ~10, !0
         16      > RETURN                                                   ~11
   35    17*     > RETURN                                                   null

End of function getraw

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Fo6Gu
function name:  get
number of ops:  9
compiled vars:  !0 = $name, !1 = $definition
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   38     1        INIT_METHOD_CALL                                         'getRaw'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN                                                   !1, $2
   39     5        INIT_DYNAMIC_CALL                                        !1
          6        DO_FCALL                                      0  $4      
          7      > RETURN                                                   $4
   40     8*     > RETURN                                                   null

End of function get

End of class DI.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.98 ms | 1404 KiB | 15 Q