3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Hello2 { public function sayHello() { echo 'Hello '; } } class World2 { public function sayWorld() { echo 'World'; } } class MyHelloWorld2 { public $hello; public $world; public function __construct() { $this->hello = new Hello2(); $this->world = new World2(); } public function sayExclamationMark() { echo '!'; } public function __call($name, $arguments) { if (method_exists($this->hello, $name)) { var_dump('$this->hello->'.$name.'()'); // $this->hello->sayHello(); // 这个是可行的 // return $this->hello->sayHello(); // 这个就报错了 //return $this->hello->$name.'()'; return $this->hello->$name(); } if (method_exists($this->world, $name)) { // return $this->world->$name(); // 或者这样写 return call_user_func([$this->word, $name]); } if (!method_exists($this->hello, $name) && !method_exists($this->world, $name)) { echo '不存在此方法'; } } } $obj = new MyHelloWorld2(); $obj->sayHello(); $obj->sayWorld(); $obj->sayExclamationMark(); // 输出: // Hello World!
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ggqAu
function name:  (null)
number of ops:  10
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   NEW                                              $1      'MyHelloWorld2'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   64     3        INIT_METHOD_CALL                                         !0, 'sayHello'
          4        DO_FCALL                                      0          
   65     5        INIT_METHOD_CALL                                         !0, 'sayWorld'
          6        DO_FCALL                                      0          
   66     7        INIT_METHOD_CALL                                         !0, 'sayExclamationMark'
          8        DO_FCALL                                      0          
   69     9      > RETURN                                                   1

Class Hello2:
Function sayhello:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ggqAu
function name:  sayHello
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ECHO                                                     'Hello+'
    8     1      > RETURN                                                   null

End of function sayhello

End of class Hello2.

Class World2:
Function sayworld:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ggqAu
function name:  sayWorld
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   ECHO                                                     'World'
   16     1      > RETURN                                                   null

End of function sayworld

End of class World2.

Class MyHelloWorld2:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ggqAu
function name:  __construct
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   NEW                                              $1      'Hello2'
          1        DO_FCALL                                      0          
          2        ASSIGN_OBJ                                               'hello'
          3        OP_DATA                                                  $1
   28     4        NEW                                              $4      'World2'
          5        DO_FCALL                                      0          
          6        ASSIGN_OBJ                                               'world'
          7        OP_DATA                                                  $4
   29     8      > RETURN                                                   null

End of function __construct

Function sayexclamationmark:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ggqAu
function name:  sayExclamationMark
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ECHO                                                     '%21'
   34     1      > RETURN                                                   null

End of function sayexclamationmark

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 45
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 43
filename:       /in/ggqAu
function name:  __call
number of ops:  46
compiled vars:  !0 = $name, !1 = $arguments
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2        INIT_FCALL                                               'method_exists'
          3        FETCH_OBJ_R                                      ~2      'hello'
          4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7      > JMPZ                                                     $3, ->17
   39     8    >   INIT_FCALL                                               'var_dump'
          9        CONCAT                                           ~4      '%24this-%3Ehello-%3E', !0
         10        CONCAT                                           ~5      ~4, '%28%29'
         11        SEND_VAL                                                 ~5
         12        DO_ICALL                                                 
   47    13        FETCH_OBJ_R                                      ~7      'hello'
         14        INIT_METHOD_CALL                                         ~7, !0
         15        DO_FCALL                                      0  $8      
         16      > RETURN                                                   $8
   50    17    >   INIT_FCALL                                               'method_exists'
         18        FETCH_OBJ_R                                      ~9      'world'
         19        SEND_VAL                                                 ~9
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $10     
         22      > JMPZ                                                     $10, ->29
   54    23    >   FETCH_OBJ_R                                      ~11     'word'
         24        INIT_ARRAY                                       ~12     ~11
         25        ADD_ARRAY_ELEMENT                                ~12     !0
         26        INIT_USER_CALL                                0          'call_user_func', ~12
         27        DO_FCALL                                      0  $13     
         28      > RETURN                                                   $13
   57    29    >   INIT_FCALL                                               'method_exists'
         30        FETCH_OBJ_R                                      ~14     'hello'
         31        SEND_VAL                                                 ~14
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $15     
         34        BOOL_NOT                                         ~16     $15
         35      > JMPZ_EX                                          ~16     ~16, ->43
         36    >   INIT_FCALL                                               'method_exists'
         37        FETCH_OBJ_R                                      ~17     'world'
         38        SEND_VAL                                                 ~17
         39        SEND_VAR                                                 !0
         40        DO_ICALL                                         $18     
         41        BOOL_NOT                                         ~19     $18
         42        BOOL                                             ~16     ~19
         43    > > JMPZ                                                     ~16, ->45
   58    44    >   ECHO                                                     '%E4%B8%8D%E5%AD%98%E5%9C%A8%E6%AD%A4%E6%96%B9%E6%B3%95'
   60    45    > > RETURN                                                   null

End of function __call

End of class MyHelloWorld2.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.91 ms | 1396 KiB | 17 Q