3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Creatable { } class FooCreatable implements Creatable { } class BarCreatable implements Creatable { } interface Creator { /** * * @param string $input * @param Creatable $creatable * @return bool */ function tryCreate($input, Creatable &$creatable = null); } class AggregateCreator implements Creator { /** * * @var Creator[] */ private $creators = []; /** * * @param Creator[] $creators */ public function __construct($creators) { $this->creators = $creators; } /** * * @param string $input * @param Creatable $creatable * @return bool */ public function tryCreate($input, Creatable &$creatable = null) { foreach ($this->creators as $creator) { if ($creator->tryCreate($input, $creatable)) { return true; } } return false; } } class FooCreator implements Creator { /** * * @param string $input * @param Creatable $creatable * @return bool */ public function tryCreate($input, Creatable &$creatable = null) { if ($input == 'foo') { $creatable = new FooCreatable; return true; } return false; } } class BarCreator implements Creator { /** * * @param string $input * @param Creatable $creatable * @return bool */ public function tryCreate($input, Creatable &$creatable = null) { if ($input == 'bar') { $creatable = new BarCreatable; return true; } return false; } } $creator = new AggregateCreator([ new FooCreator, new BarCreator, ]); $creatable = null; var_dump($creator->tryCreate('foo', $creatable), $creatable); $creatable = null; var_dump($creator->tryCreate('bar', $creatable), $creatable); $creatable = null; var_dump($creator->tryCreate('qux', $creatable), $creatable);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Gu0r3
function name:  (null)
number of ops:  43
compiled vars:  !0 = $creator, !1 = $creatable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'foocreatable'
   13     1        DECLARE_CLASS                                            'barcreatable'
   31     2        DECLARE_CLASS                                            'aggregatecreator'
   69     3        DECLARE_CLASS                                            'foocreator'
   90     4        DECLARE_CLASS                                            'barcreator'
  111     5        NEW                                              $2      'AggregateCreator'
  112     6        NEW                                              $3      'FooCreator'
          7        DO_FCALL                                      0          
          8        INIT_ARRAY                                       ~5      $3
  113     9        NEW                                              $6      'BarCreator'
         10        DO_FCALL                                      0          
         11        ADD_ARRAY_ELEMENT                                ~5      $6
         12        SEND_VAL_EX                                              ~5
         13        DO_FCALL                                      0          
  111    14        ASSIGN                                                   !0, $2
  116    15        ASSIGN                                                   !1, null
  117    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !0, 'tryCreate'
         18        SEND_VAL_EX                                              'foo'
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0  $11     
         21        SEND_VAR                                                 $11
         22        SEND_VAR                                                 !1
         23        DO_ICALL                                                 
  119    24        ASSIGN                                                   !1, null
  120    25        INIT_FCALL                                               'var_dump'
         26        INIT_METHOD_CALL                                         !0, 'tryCreate'
         27        SEND_VAL_EX                                              'bar'
         28        SEND_VAR_EX                                              !1
         29        DO_FCALL                                      0  $14     
         30        SEND_VAR                                                 $14
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                                 
  122    33        ASSIGN                                                   !1, null
  123    34        INIT_FCALL                                               'var_dump'
         35        INIT_METHOD_CALL                                         !0, 'tryCreate'
         36        SEND_VAL_EX                                              'qux'
         37        SEND_VAR_EX                                              !1
         38        DO_FCALL                                      0  $17     
         39        SEND_VAR                                                 $17
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Class Creatable: [no user functions]
Class FooCreatable: [no user functions]
Class BarCreatable: [no user functions]
Class Creator:
Function trycreate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Gu0r3
function name:  tryCreate
number of ops:  3
compiled vars:  !0 = $input, !1 = $creatable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
          2      > RETURN                                                   null

End of function trycreate

End of class Creator.

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

End of function __construct

Function trycreate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/Gu0r3
function name:  tryCreate
number of ops:  16
compiled vars:  !0 = $input, !1 = $creatable, !2 = $creator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   57     2        FETCH_OBJ_R                                      ~3      'creators'
          3      > FE_RESET_R                                       $4      ~3, ->13
          4    > > FE_FETCH_R                                               $4, !2, ->13
   59     5    >   INIT_METHOD_CALL                                         !2, 'tryCreate'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $5      
          9      > JMPZ                                                     $5, ->12
   61    10    >   FE_FREE                                                  $4
         11      > RETURN                                                   <true>
   57    12    > > JMP                                                      ->4
         13    >   FE_FREE                                                  $4
   64    14      > RETURN                                                   <false>
   65    15*     > RETURN                                                   null

End of function trycreate

End of class AggregateCreator.

Class FooCreator:
Function trycreate:
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/Gu0r3
function name:  tryCreate
number of ops:  10
compiled vars:  !0 = $input, !1 = $creatable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   80     2        IS_EQUAL                                                 !0, 'foo'
          3      > JMPZ                                                     ~2, ->8
   82     4    >   NEW                                              $3      'FooCreatable'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $3
   83     7      > RETURN                                                   <true>
   85     8    > > RETURN                                                   <false>
   86     9*     > RETURN                                                   null

End of function trycreate

End of class FooCreator.

Class BarCreator:
Function trycreate:
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/Gu0r3
function name:  tryCreate
number of ops:  10
compiled vars:  !0 = $input, !1 = $creatable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
  101     2        IS_EQUAL                                                 !0, 'bar'
          3      > JMPZ                                                     ~2, ->8
  103     4    >   NEW                                              $3      'BarCreatable'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $3
  104     7      > RETURN                                                   <true>
  106     8    > > RETURN                                                   <false>
  107     9*     > RETURN                                                   null

End of function trycreate

End of class BarCreator.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.78 ms | 1404 KiB | 15 Q