3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); interface Factory { public function build(): Product; } interface Product { } class A implements Product { } class B implements Product { } class FA implements Factory { public function build(): Product { return new A; } } class FB implements Factory { public function build(): Product { return new A; } } class Client { private $f; public function __construct(Factory $f) { $this->f = $f; } public function payload() { var_dump($this->f->build()); } } $fa = new FA; $clientA = new Client($fa); $clientA->payload(); $fb = new FB; $clientB = new Client($fb); $clientB->payload();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S5aRF
function name:  (null)
number of ops:  23
compiled vars:  !0 = $fa, !1 = $clientA, !2 = $fb, !3 = $clientB
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   DECLARE_CLASS                                            'a'
   18     1        DECLARE_CLASS                                            'b'
   22     2        DECLARE_CLASS                                            'fa'
   30     3        DECLARE_CLASS                                            'fb'
   53     4        NEW                                              $4      'FA'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $4
   54     7        NEW                                              $7      'Client'
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $7
   55    11        INIT_METHOD_CALL                                         !1, 'payload'
         12        DO_FCALL                                      0          
   57    13        NEW                                              $11     'FB'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !2, $11
   58    16        NEW                                              $14     'Client'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
         19        ASSIGN                                                   !3, $14
   59    20        INIT_METHOD_CALL                                         !3, 'payload'
         21        DO_FCALL                                      0          
         22      > RETURN                                                   1

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

End of function build

End of class Factory.

Class Product: [no user functions]
Class A: [no user functions]
Class B: [no user functions]
Class FA:
Function build:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S5aRF
function name:  build
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $0      'A'
          1        DO_FCALL                                      0          
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   27     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function build

End of class FA.

Class FB:
Function build:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S5aRF
function name:  build
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   NEW                                              $0      'A'
          1        DO_FCALL                                      0          
          2        VERIFY_RETURN_TYPE                                       $0
          3      > RETURN                                                   $0
   35     4*       VERIFY_RETURN_TYPE                                       
          5*     > RETURN                                                   null

End of function build

End of class FB.

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

End of function __construct

Function payload:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/S5aRF
function name:  payload
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   INIT_FCALL                                               'var_dump'
          1        FETCH_OBJ_R                                      ~0      'f'
          2        INIT_METHOD_CALL                                         ~0, 'build'
          3        DO_FCALL                                      0  $1      
          4        SEND_VAR                                                 $1
          5        DO_ICALL                                                 
   50     6      > RETURN                                                   null

End of function payload

End of class Client.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.15 ms | 1003 KiB | 14 Q