3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Forest { public function treesHeight(): float; } final class EarthForest implements Forest { public function treesHeight(): float { return 123 * 456; } } interface Plains { public function windPower(): float; } final class EarthPlains implements Plains { public function windPower(): float { return 10; } } final class MarsPlains implements Plains { public function windPower(): float { return 250; } } interface Sea { public function noise(): string; } final class EarthSea implements Sea { public function noise(): string { return 'Shush! Shush!'; } } interface TerrainFactory { public function makeSea(): Sea; public function makeForest(): Forest; public function makePlains(): Plains; } final class EarthTerrainFactory implements TerrainFactory { public function makeForest(): EarthForest { return new EarthForest(); } public function makePlains(): EarthPlains { return new EarthPlains(); } public function makeSea(): EarthSea { return new EarthSea(); } } // boilerplate code for null case final class NullForest implements Forest { public function treesHeight(): float { return 0.; } } final class NullPlains implements Plains { public function windPower(): float { return 0.; } } final class NullSea implements Sea { public function noise(): string { return ''; } } final class NullTerrainFactory implements TerrainFactory { public function makeForest(): NullForest { return new NullForest(); } public function makePlains(): NullPlains { return new NullPlains(); } public function makeSea(): NullSea { return new NullSea(); } } // end boilerplate code class TerrainFactoryFactory { public function make(string $type) { return match($type) { 'earth' => new EarthTerrainFactory(), default => new NullTerrainFactory(), }; } } $type = 'earth'; $factoryFactory = new TerrainFactoryFactory(); $terrainFactory = $factoryFactory->make($type); $forest = $terrainFactory->makeForest(); $plains = $terrainFactory->makePlains(); $sea = $terrainFactory->makeSea(); var_dump($forest->treesHeight()); var_dump($plains->windPower()); var_dump($sea->noise());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9D9LU
function name:  (null)
number of ops:  42
compiled vars:  !0 = $type, !1 = $factoryFactory, !2 = $terrainFactory, !3 = $forest, !4 = $plains, !5 = $sea
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_CLASS                                            'earthforest'
   22     1        DECLARE_CLASS                                            'earthplains'
   30     2        DECLARE_CLASS                                            'marsplains'
   43     3        DECLARE_CLASS                                            'earthsea'
   59     4        DECLARE_CLASS                                            'earthterrainfactory'
   81     5        DECLARE_CLASS                                            'nullforest'
   89     6        DECLARE_CLASS                                            'nullplains'
   97     7        DECLARE_CLASS                                            'nullsea'
  106     8        DECLARE_CLASS                                            'nullterrainfactory'
  138     9        ASSIGN                                                   !0, 'earth'
  139    10        NEW                                              $7      'TerrainFactoryFactory'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $7
  140    13        INIT_METHOD_CALL                                         !1, 'make'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0  $10     
         16        ASSIGN                                                   !2, $10
  142    17        INIT_METHOD_CALL                                         !2, 'makeForest'
         18        DO_FCALL                                      0  $12     
         19        ASSIGN                                                   !3, $12
  143    20        INIT_METHOD_CALL                                         !2, 'makePlains'
         21        DO_FCALL                                      0  $14     
         22        ASSIGN                                                   !4, $14
  144    23        INIT_METHOD_CALL                                         !2, 'makeSea'
         24        DO_FCALL                                      0  $16     
         25        ASSIGN                                                   !5, $16
  146    26        INIT_FCALL                                               'var_dump'
         27        INIT_METHOD_CALL                                         !3, 'treesHeight'
         28        DO_FCALL                                      0  $18     
         29        SEND_VAR                                                 $18
         30        DO_ICALL                                                 
  147    31        INIT_FCALL                                               'var_dump'
         32        INIT_METHOD_CALL                                         !4, 'windPower'
         33        DO_FCALL                                      0  $20     
         34        SEND_VAR                                                 $20
         35        DO_ICALL                                                 
  148    36        INIT_FCALL                                               'var_dump'
         37        INIT_METHOD_CALL                                         !5, 'noise'
         38        DO_FCALL                                      0  $22     
         39        SEND_VAR                                                 $22
         40        DO_ICALL                                                 
         41      > RETURN                                                   1

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

End of function treesheight

End of class Forest.

Class EarthForest:
Function treesheight:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9D9LU
function name:  treesHeight
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   VERIFY_RETURN_TYPE                               ~0      56088
          1      > RETURN                                                   ~0
   14     2*       VERIFY_RETURN_TYPE                                       
          3*     > RETURN                                                   null

End of function treesheight

End of class EarthForest.

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

End of function windpower

End of class Plains.

Class EarthPlains:
Function windpower:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9D9LU
function name:  windPower
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   VERIFY_RETURN_TYPE                               ~0      10
          1      > RETURN                                                   ~0
   27     2*       VERIFY_RETURN_TYPE                                       
          3*     > RETURN                                                   null

End of function windpower

End of class EarthPlains.

Class MarsPlains:
Function windpower:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9D9LU
function name:  windPower
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   VERIFY_RETURN_TYPE                               ~0      250
          1      > RETURN                                                   ~0
   35     2*       VERIFY_RETURN_TYPE                                       
          3*     > RETURN                                                   null

End of function windpower

End of class MarsPlains.

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

End of function noise

End of class Sea.

Class EarthSea:
Function noise:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9D9LU
function name:  noise
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E > > RETURN                                                   'Shush%21+Shush%21'
   48     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function noise

End of class EarthSea.

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

End of function makesea

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

End of function makeforest

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

End of function makeplains

End of class TerrainFactory.

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

End of function makeforest

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

End of function makeplains

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

End of function makesea

End of class EarthTerrainFactory.

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

End of function treesheight

End of class NullForest.

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

End of function windpower

End of class NullPlains.

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

End of function noise

End of class NullSea.

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

End of function makeforest

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

End of function makeplains

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

End of function makesea

End of class NullTerrainFactory.

Class TerrainFactoryFactory:
Function make:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
filename:       /in/9D9LU
function name:  make
number of ops:  14
compiled vars:  !0 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  128     0  E >   RECV                                             !0      
  131     1        IS_IDENTICAL                                             !0, 'earth'
          2      > JMPNZ                                                    ~1, ->4
          3    > > JMP                                                      ->8
          4    >   NEW                                              $2      'EarthTerrainFactory'
          5        DO_FCALL                                      0          
          6        QM_ASSIGN                                        ~4      $2
          7      > JMP                                                      ->12
  132     8    >   NEW                                              $5      'NullTerrainFactory'
          9        DO_FCALL                                      0          
         10        QM_ASSIGN                                        ~4      $5
         11      > JMP                                                      ->12
         12    > > RETURN                                                   ~4
  134    13*     > RETURN                                                   null

End of function make

End of class TerrainFactoryFactory.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.01 ms | 1015 KiB | 14 Q