3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DepInterface {} class Dependency implements DepInterface { public function __construct($param1, $param2) {} } class NotDI { protected $dep; public function __construct() { // 1. if we ever change the constructor of the Dependency class we now need to // go fiddle with the implementation in every class ever. // 2. not only that, now this class needs to know the proper configuration for // its dependency, which is not necessarily something it need be responsible for // 3. we now have a hard dependency on this one, concrete implementation. $this->dep = new Dependency('foo', 'bar'); } } class IsDI { protected $dep; public function __construct(DepInterface $dep) { // Now we no longer need care how the object is instantiated, or what it even is // so long as it implements the interface that we are expecting. $this->dep = $dep; } } $dep = new Dependency('foo', 'bar'); $johnny = new IsDI($dep);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Td9oe
function name:  (null)
number of ops:  11
compiled vars:  !0 = $dep, !1 = $johnny
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   DECLARE_CLASS                                            'dependency'
   32     1        NEW                                              $2      'Dependency'
          2        SEND_VAL_EX                                              'foo'
          3        SEND_VAL_EX                                              'bar'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   33     6        NEW                                              $5      'IsDI'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $5
         10      > RETURN                                                   1

Class DepInterface: [no user functions]
Class Dependency:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Td9oe
function name:  __construct
number of ops:  3
compiled vars:  !0 = $param1, !1 = $param2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > RETURN                                                   null

End of function __construct

End of class Dependency.

Class NotDI:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Td9oe
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $1      'Dependency'
          1        SEND_VAL_EX                                              'foo'
          2        SEND_VAL_EX                                              'bar'
          3        DO_FCALL                                      0          
          4        ASSIGN_OBJ                                               'dep'
          5        OP_DATA                                                  $1
   19     6      > RETURN                                                   null

End of function __construct

End of class NotDI.

Class IsDI:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Td9oe
function name:  __construct
number of ops:  4
compiled vars:  !0 = $dep
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   28     1        ASSIGN_OBJ                                               'dep'
          2        OP_DATA                                                  !0
   29     3      > RETURN                                                   null

End of function __construct

End of class IsDI.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.33 ms | 1395 KiB | 13 Q