3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Product{ public function GetName(); } class ConcreteProductA implements Product{ public function GetName() { return "ProductA"; } } class ConcreteProductB implements Product{ public function GetName() { return "ProductB"; } } interface Creator{ public function FactoryMethod(); } class ConcreteCreatorA implements Creator{ public function FactoryMethod() { return new ConcreteProductA(); } } class ConcreteCreatorB implements Creator{ public function FactoryMethod() { return new ConcreteProductB(); } } // An array of creators $creators = array( new ConcreteCreatorA(), new ConcreteCreatorB() ); // Iterate over creators and create products for($i = 0; $i < count($creators); $i++){ $products[] = $creators[$i]->FactoryMethod(); } header("content-type:text/plain"); echo var_export($products); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 13
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 13
Branch analysis from position: 22
Branch analysis from position: 13
filename:       /in/RCh39
function name:  (null)
number of ops:  30
compiled vars:  !0 = $creators, !1 = $i, !2 = $products
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   DECLARE_CLASS                                            'concreteproducta'
   10     1        DECLARE_CLASS                                            'concreteproductb'
   18     2        DECLARE_CLASS                                            'concretecreatora'
   22     3        DECLARE_CLASS                                            'concretecreatorb'
   27     4        NEW                                              $3      'ConcreteCreatorA'
          5        DO_FCALL                                      0          
          6        INIT_ARRAY                                       ~5      $3
          7        NEW                                              $6      'ConcreteCreatorB'
          8        DO_FCALL                                      0          
          9        ADD_ARRAY_ELEMENT                                ~5      $6
         10        ASSIGN                                                   !0, ~5
   29    11        ASSIGN                                                   !1, 0
         12      > JMP                                                      ->19
   30    13    >   FETCH_DIM_R                                      ~11     !0, !1
         14        INIT_METHOD_CALL                                         ~11, 'FactoryMethod'
         15        DO_FCALL                                      0  $12     
         16        ASSIGN_DIM                                               !2
         17        OP_DATA                                                  $12
   29    18        PRE_INC                                                  !1
         19    >   COUNT                                            ~14     !0
         20        IS_SMALLER                                               !1, ~14
         21      > JMPNZ                                                    ~15, ->13
   33    22    >   INIT_FCALL                                               'header'
         23        SEND_VAL                                                 'content-type%3Atext%2Fplain'
         24        DO_ICALL                                                 
   34    25        INIT_FCALL                                               'var_export'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                         $17     
         28        ECHO                                                     $17
   36    29      > RETURN                                                   1

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

End of function getname

End of class Product.

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

End of function getname

End of class ConcreteProductA.

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

End of function getname

End of class ConcreteProductB.

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

End of function factorymethod

End of class Creator.

Class ConcreteCreatorA:
Function factorymethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCh39
function name:  FactoryMethod
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $0      'ConcreteProductA'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
          3*     > RETURN                                                   null

End of function factorymethod

End of class ConcreteCreatorA.

Class ConcreteCreatorB:
Function factorymethod:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RCh39
function name:  FactoryMethod
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   NEW                                              $0      'ConcreteProductB'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
          3*     > RETURN                                                   null

End of function factorymethod

End of class ConcreteCreatorB.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.96 ms | 1404 KiB | 17 Q