3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class ToolSetFactory { protected array $products = []; public function make(string $productName, ...$params): Drawable { if ($product = $this->products[$productName] ?? null) return new $product($params); return new NullProduct(); } } class BasicToolSetFactory extends ToolSetFactory { public function __construct() { $this->products['general'] = GeneralProduct::class; $this->products['arrows'] = ArrowsProduct::class; } } // Interfaces interface Drawable { public function draw(): void; } interface General extends Drawable {} interface Arrows extends Drawable {} // Product classes class GeneralProduct implements General { public function draw(): void { print "Drawing general elements\n"; } // Other methods } class ArrowsProduct implements Arrows { public function draw(): void { print "Drawing arrows elements\n"; } // Other methods } // Client code class BasicToolSet { public function createToolSet(ToolSetFactory $factory): void { $general = $factory->make('general'); $arrows = $factory->make('arrows'); foreach ([$general, $arrows] as $product) { $product->draw(); } } } // Usage $basicToolSetFactory = new BasicToolSetFactory(); $basicToolSet = new BasicToolSet(); $basicToolSet->createToolSet($basicToolSetFactory);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gWUPr
function name:  (null)
number of ops:  14
compiled vars:  !0 = $basicToolSetFactory, !1 = $basicToolSet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   DECLARE_CLASS                                            'general'
   35     1        DECLARE_CLASS                                            'arrows'
   40     2        DECLARE_CLASS                                            'generalproduct'
   50     3        DECLARE_CLASS                                            'arrowsproduct'
   80     4        NEW                                              $2      'BasicToolSetFactory'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   82     7        NEW                                              $5      'BasicToolSet'
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !1, $5
   83    10        INIT_METHOD_CALL                                         !1, 'createToolSet'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Class ToolSetFactory:
Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gWUPr
function name:  make
number of ops:  20
compiled vars:  !0 = $productName, !1 = $params, !2 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
    9     2        FETCH_OBJ_IS                                     ~3      'products'
          3        FETCH_DIM_IS                                     ~4      ~3, !0
          4        COALESCE                                         ~5      ~4
          5        QM_ASSIGN                                        ~5      null
          6        ASSIGN                                           ~6      !2, ~5
          7      > JMPZ                                                     ~6, ->14
   10     8    >   FETCH_CLASS                                   0  $7      !2
          9        NEW                                              $8      $7
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        VERIFY_RETURN_TYPE                                       $8
         13      > RETURN                                                   $8
   12    14    >   NEW                                              $10     'NullProduct'
         15        DO_FCALL                                      0          
         16        VERIFY_RETURN_TYPE                                       $10
         17      > RETURN                                                   $10
   13    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function make

End of class ToolSetFactory.

Class BasicToolSetFactory:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gWUPr
function name:  __construct
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_W                                      $0      'products'
          1        ASSIGN_DIM                                               $0, 'general'
          2        OP_DATA                                                  'GeneralProduct'
   21     3        FETCH_OBJ_W                                      $2      'products'
          4        ASSIGN_DIM                                               $2, 'arrows'
          5        OP_DATA                                                  'ArrowsProduct'
   22     6      > RETURN                                                   null

End of function __construct

Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gWUPr
function name:  make
number of ops:  20
compiled vars:  !0 = $productName, !1 = $params, !2 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
    9     2        FETCH_OBJ_IS                                     ~3      'products'
          3        FETCH_DIM_IS                                     ~4      ~3, !0
          4        COALESCE                                         ~5      ~4
          5        QM_ASSIGN                                        ~5      null
          6        ASSIGN                                           ~6      !2, ~5
          7      > JMPZ                                                     ~6, ->14
   10     8    >   FETCH_CLASS                                   0  $7      !2
          9        NEW                                              $8      $7
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        VERIFY_RETURN_TYPE                                       $8
         13      > RETURN                                                   $8
   12    14    >   NEW                                              $10     'NullProduct'
         15        DO_FCALL                                      0          
         16        VERIFY_RETURN_TYPE                                       $10
         17      > RETURN                                                   $10
   13    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function make

End of class BasicToolSetFactory.

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

End of function draw

End of class Drawable.

Class General: [no user functions]
Class Arrows: [no user functions]
Class GeneralProduct:
Function draw:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gWUPr
function name:  draw
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ECHO                                                     'Drawing+general+elements%0A'
   45     1      > RETURN                                                   null

End of function draw

End of class GeneralProduct.

Class ArrowsProduct:
Function draw:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gWUPr
function name:  draw
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   ECHO                                                     'Drawing+arrows+elements%0A'
   55     1      > RETURN                                                   null

End of function draw

End of class ArrowsProduct.

Class BasicToolSet:
Function createtoolset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/gWUPr
function name:  createToolSet
number of ops:  18
compiled vars:  !0 = $factory, !1 = $general, !2 = $arrows, !3 = $product
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
   67     1        INIT_METHOD_CALL                                         !0, 'make'
          2        SEND_VAL_EX                                              'general'
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   69     5        INIT_METHOD_CALL                                         !0, 'make'
          6        SEND_VAL_EX                                              'arrows'
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   71     9        INIT_ARRAY                                       ~8      !1
         10        ADD_ARRAY_ELEMENT                                ~8      !2
         11      > FE_RESET_R                                       $9      ~8, ->16
         12    > > FE_FETCH_R                                               $9, !3, ->16
   72    13    >   INIT_METHOD_CALL                                         !3, 'draw'
         14        DO_FCALL                                      0          
   71    15      > JMP                                                      ->12
         16    >   FE_FREE                                                  $9
   74    17      > RETURN                                                   null

End of function createtoolset

End of class BasicToolSet.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.2 ms | 988 KiB | 13 Q