3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface IWidget { } class WidgetA implements IWidget { } class WidgetB implements IWidget { } interface IWidgetFactory { function tryCreateWidget($someInput, IWidget &$widget = null); } class WidgetAFactory implements IWidgetFactory { public function tryCreateWidget($someInput, IWidget &$widget = null) { if ($someInput < 7) { $widget = new WidgetA(); return true; } return false; } } class WidgetBFactory implements IWidgetFactory { public function tryCreateWidget($someInput, IWidget &$widget = null) { if ($someInput > 10) { $widget = new WidgetB(); return true; } return false; } } class WidgetFactoryAggregate implements IWidgetFactory { private $widgetFactories = []; function __construct(array $widgetFactories) { $this->widgetFactories = $widgetFactories; } public function tryCreateWidget($someInput, IWidget &$widget = null) { foreach ($this->widgetFactories as $widgetFactory) { if ($widgetFactory->tryCreateWidget($someInput)) { return true; } } return false; } } $widgetFactory = new WidgetFactoryAggregate([ new WidgetAFactory(), new WidgetBFactory(), ]); foreach ([1, 5, 15, 9] as $someInput) { $widget = null; if ($widgetFactory->tryCreateWidget($someInput, $widget)) { var_dump($widget); continue; } var_dump("Failed to create widget for {$someInput}"); break; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 34
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 34
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
Branch analysis from position: 34
filename:       /in/iSsIQ
function name:  (null)
number of ops:  36
compiled vars:  !0 = $widgetFactory, !1 = $someInput, !2 = $widget
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'widgeta'
   13     1        DECLARE_CLASS                                            'widgetb'
   25     2        DECLARE_CLASS                                            'widgetafactory'
   39     3        DECLARE_CLASS                                            'widgetbfactory'
   53     4        DECLARE_CLASS                                            'widgetfactoryaggregate'
   75     5        NEW                                              $3      'WidgetFactoryAggregate'
   76     6        NEW                                              $4      'WidgetAFactory'
          7        DO_FCALL                                      0          
          8        INIT_ARRAY                                       ~6      $4
   77     9        NEW                                              $7      'WidgetBFactory'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~6      $7
         12        SEND_VAL_EX                                              ~6
         13        DO_FCALL                                      0          
   75    14        ASSIGN                                                   !0, $3
   80    15      > FE_RESET_R                                       $11     <array>, ->34
         16    > > FE_FETCH_R                                               $11, !1, ->34
   81    17    >   ASSIGN                                                   !2, null
   82    18        INIT_METHOD_CALL                                         !0, 'tryCreateWidget'
         19        SEND_VAR_EX                                              !1
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0  $13     
         22      > JMPZ                                                     $13, ->27
   83    23    >   INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                                 
   84    26      > JMP                                                      ->16
   86    27    >   INIT_FCALL                                               'var_dump'
         28        NOP                                                      
         29        FAST_CONCAT                                      ~15     'Failed+to+create+widget+for+', !1
         30        SEND_VAL                                                 ~15
         31        DO_ICALL                                                 
   87    32      > JMP                                                      ->34
   80    33*       JMP                                                      ->16
         34    >   FE_FREE                                                  $11
   88    35      > RETURN                                                   1

Class IWidget: [no user functions]
Class WidgetA: [no user functions]
Class WidgetB: [no user functions]
Class IWidgetFactory:
Function trycreatewidget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSsIQ
function name:  tryCreateWidget
number of ops:  3
compiled vars:  !0 = $someInput, !1 = $widget
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2      > RETURN                                                   null

End of function trycreatewidget

End of class IWidgetFactory.

Class WidgetAFactory:
Function trycreatewidget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSsIQ
function name:  tryCreateWidget
number of ops:  10
compiled vars:  !0 = $someInput, !1 = $widget
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   30     2        IS_SMALLER                                               !0, 7
          3      > JMPZ                                                     ~2, ->8
   31     4    >   NEW                                              $3      'WidgetA'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $3
   32     7      > RETURN                                                   <true>
   34     8    > > RETURN                                                   <false>
   35     9*     > RETURN                                                   null

End of function trycreatewidget

End of class WidgetAFactory.

Class WidgetBFactory:
Function trycreatewidget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iSsIQ
function name:  tryCreateWidget
number of ops:  10
compiled vars:  !0 = $someInput, !1 = $widget
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   44     2        IS_SMALLER                                               10, !0
          3      > JMPZ                                                     ~2, ->8
   45     4    >   NEW                                              $3      'WidgetB'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $3
   46     7      > RETURN                                                   <true>
   48     8    > > RETURN                                                   <false>
   49     9*     > RETURN                                                   null

End of function trycreatewidget

End of class WidgetBFactory.

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

End of function __construct

Function trycreatewidget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/iSsIQ
function name:  tryCreateWidget
number of ops:  15
compiled vars:  !0 = $someInput, !1 = $widget, !2 = $widgetFactory
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   65     2        FETCH_OBJ_R                                      ~3      'widgetFactories'
          3      > FE_RESET_R                                       $4      ~3, ->12
          4    > > FE_FETCH_R                                               $4, !2, ->12
   66     5    >   INIT_METHOD_CALL                                         !2, 'tryCreateWidget'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $5      
          8      > JMPZ                                                     $5, ->11
   67     9    >   FE_FREE                                                  $4
         10      > RETURN                                                   <true>
   65    11    > > JMP                                                      ->4
         12    >   FE_FREE                                                  $4
   70    13      > RETURN                                                   <false>
   71    14*     > RETURN                                                   null

End of function trycreatewidget

End of class WidgetFactoryAggregate.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.79 ms | 1404 KiB | 15 Q