3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function bar() { var_dump(__METHOD__); } public function baz() { var_dump(__METHOD__); } public function bat() { var_dump(__METHOD__); return 'bat!'; } } class FluentWrapper { private $instance; private $fluentMethods; public function __construct($instance, array $fluentMethods = []) { $this->instance = $instance; $this->fluentMethods = $fluentMethods; } public function __call($name, $args) { $result = $this->instance->{$name}(...$args); return in_array($name, $this->fluentMethods) ? $this : $result; } } $foo = new FluentWrapper(new Foo(), ['bar', 'baz']); $bat = $foo ->bar() ->baz() ->bar() ->baz() ->bat(); print $bat."\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p3a44
function name:  (null)
number of ops:  21
compiled vars:  !0 = $foo, !1 = $bat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   NEW                                              $2      'FluentWrapper'
          1        NEW                                              $3      'Foo'
          2        DO_FCALL                                      0          
          3        SEND_VAR_NO_REF_EX                                       $3
          4        SEND_VAL_EX                                              <array>
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   45     7        INIT_METHOD_CALL                                         !0, 'bar'
          8        DO_FCALL                                      0  $7      
   46     9        INIT_METHOD_CALL                                         $7, 'baz'
         10        DO_FCALL                                      0  $8      
   47    11        INIT_METHOD_CALL                                         $8, 'bar'
         12        DO_FCALL                                      0  $9      
   48    13        INIT_METHOD_CALL                                         $9, 'baz'
         14        DO_FCALL                                      0  $10     
   49    15        INIT_METHOD_CALL                                         $10, 'bat'
         16        DO_FCALL                                      0  $11     
   44    17        ASSIGN                                                   !1, $11
   51    18        CONCAT                                           ~13     !1, '%0A'
         19        ECHO                                                     ~13
         20      > RETURN                                                   1

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

End of function bar

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

End of function baz

Function bat:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p3a44
function name:  bat
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'var_dump'
          1        SEND_VAL                                                 'Foo%3A%3Abat'
          2        DO_ICALL                                                 
   19     3      > RETURN                                                   'bat%21'
   20     4*     > RETURN                                                   null

End of function bat

End of class Foo.

Class FluentWrapper:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p3a44
function name:  __construct
number of ops:  7
compiled vars:  !0 = $instance, !1 = $fluentMethods
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   29     2        ASSIGN_OBJ                                               'instance'
          3        OP_DATA                                                  !0
   30     4        ASSIGN_OBJ                                               'fluentMethods'
          5        OP_DATA                                                  !1
   31     6      > RETURN                                                   null

End of function __construct

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p3a44
function name:  __call
number of ops:  20
compiled vars:  !0 = $name, !1 = $args, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   35     2        FETCH_OBJ_R                                      ~3      'instance'
          3        INIT_METHOD_CALL                                         ~3, !0
          4        SEND_UNPACK                                              !1
          5        CHECK_UNDEF_ARGS                                         
          6        DO_FCALL                                      1  $4      
          7        ASSIGN                                                   !2, $4
   37     8        INIT_FCALL                                               'in_array'
          9        SEND_VAR                                                 !0
         10        FETCH_OBJ_R                                      ~6      'fluentMethods'
         11        SEND_VAL                                                 ~6
         12        DO_ICALL                                         $7      
         13      > JMPZ                                                     $7, ->17
         14    >   FETCH_THIS                                       ~8      
         15        QM_ASSIGN                                        ~9      ~8
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~9      !2
         18    > > RETURN                                                   ~9
   38    19*     > RETURN                                                   null

End of function __call

End of class FluentWrapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.73 ms | 1400 KiB | 17 Q