3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Proxy { private $object; private $factoryArray = []; public function __construct($object, array $factoryArray = []) { $this->object = $object; $this->factoryArray = $factoryArray; } public function __call($name, array $argumentArray) { $reflection = new ReflectionMethod($this->object, $name); $function = $reflection->getClosure($this->object)->bindTo($this, null); return call_user_func_array($function, $argumentArray); } public function __get($name) { if ($name[0] == '!') { return $this->__getFactory(substr($name, 1)); } } public function __getFactory($name) { if (isset($this->factoryArray[$name])) { return new self($this->factoryArray[$name](), $this->factoryArray); } } } class Foo { public function doStuff1() { $this->{'!Bar'}->doStuff2(); } } class Bar { public function doStuff2() { $this->{'!Qux'}->doStuff3(); } } class Qux { public function doStuff3() { var_dump(__METHOD__); } } $foo = new Proxy(new Foo, [ 'Bar' => function () { return new Bar; }, 'Qux' => function () { return new Qux; }, ]); $foo->doStuff1();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  (null)
number of ops:  14
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   NEW                                              $1      'Proxy'
          1        NEW                                              $2      'Foo'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $2
   72     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUXibA%3A72%240'
   74     5        INIT_ARRAY                                       ~5      ~4, 'Bar'
   75     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUXibA%3A75%241'
   77     7        ADD_ARRAY_ELEMENT                                ~5      ~6, 'Qux'
          8        SEND_VAL_EX                                              ~5
          9        DO_FCALL                                      0          
   71    10        ASSIGN                                                   !0, $1
   80    11        INIT_METHOD_CALL                                         !0, 'doStuff1'
         12        DO_FCALL                                      0          
         13      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FUXibA%3A72%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   NEW                                              $0      'Bar'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   74     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FUXibA%3A72%240

Function %00%7Bclosure%7D%2Fin%2FUXibA%3A75%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   NEW                                              $0      'Qux'
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
   77     3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FUXibA%3A75%241

Class Proxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  __construct
number of ops:  7
compiled vars:  !0 = $object, !1 = $factoryArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   12     2        ASSIGN_OBJ                                               'object'
          3        OP_DATA                                                  !0
   13     4        ASSIGN_OBJ                                               'factoryArray'
          5        OP_DATA                                                  !1
   14     6      > RETURN                                                   null

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  __call
number of ops:  26
compiled vars:  !0 = $name, !1 = $argumentArray, !2 = $reflection, !3 = $function
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   18     2        NEW                                              $4      'ReflectionMethod'
          3        CHECK_FUNC_ARG                                           
          4        FETCH_OBJ_FUNC_ARG                               $5      'object'
          5        SEND_FUNC_ARG                                            $5
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $4
   19     9        INIT_METHOD_CALL                                         !2, 'getClosure'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $8      'object'
         12        SEND_FUNC_ARG                                            $8
         13        DO_FCALL                                      0  $9      
         14        INIT_METHOD_CALL                                         $9, 'bindTo'
         15        FETCH_THIS                                       $10     
         16        SEND_VAR_EX                                              $10
         17        SEND_VAL_EX                                              null
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !3, $11
   20    20        INIT_USER_CALL                                0          'call_user_func_array', !3
         21        SEND_ARRAY                                               !1
         22        CHECK_UNDEF_ARGS                                         
         23        DO_FCALL                                      0  $13     
         24      > RETURN                                                   $13
   21    25*     > RETURN                                                   null

End of function __call

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  __get
number of ops:  13
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        FETCH_DIM_R                                      ~1      !0, 0
          2        IS_EQUAL                                                 ~1, '%21'
          3      > JMPZ                                                     ~2, ->12
   27     4    >   INIT_METHOD_CALL                                         '__getFactory'
          5        INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 1
          8        DO_ICALL                                         $3      
          9        SEND_VAR_NO_REF_EX                                       $3
         10        DO_FCALL                                      0  $4      
         11      > RETURN                                                   $4
   29    12    > > RETURN                                                   null

End of function __get

Function __getfactory:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  __getFactory
number of ops:  16
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   33     1        FETCH_OBJ_IS                                     ~1      'factoryArray'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->15
   35     4    >   NEW                          self                $3      
          5        FETCH_OBJ_R                                      ~4      'factoryArray'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7        INIT_DYNAMIC_CALL                                        ~5
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR_NO_REF_EX                                       $6
         10        CHECK_FUNC_ARG                                           
         11        FETCH_OBJ_FUNC_ARG                               $7      'factoryArray'
         12        SEND_FUNC_ARG                                            $7
         13        DO_FCALL                                      0          
         14      > RETURN                                                   $3
   37    15    > > RETURN                                                   null

End of function __getfactory

End of class Proxy.

Class Foo:
Function dostuff1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  doStuff1
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   FETCH_OBJ_R                                      ~0      '%21Bar'
          1        INIT_METHOD_CALL                                         ~0, 'doStuff2'
          2        DO_FCALL                                      0          
   47     3      > RETURN                                                   null

End of function dostuff1

End of class Foo.

Class Bar:
Function dostuff2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  doStuff2
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   FETCH_OBJ_R                                      ~0      '%21Qux'
          1        INIT_METHOD_CALL                                         ~0, 'doStuff3'
          2        DO_FCALL                                      0          
   57     3      > RETURN                                                   null

End of function dostuff2

End of class Bar.

Class Qux:
Function dostuff3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UXibA
function name:  doStuff3
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'Qux%3A%3AdoStuff3'
          2        DO_ICALL                                                 
   67     3      > RETURN                                                   null

End of function dostuff3

End of class Qux.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.72 ms | 1413 KiB | 17 Q