3v4l.org

run code in 300+ PHP versions simultaneously
<?php function call_user_func_fixed() { // Not much point in writing all that logic out twice, just require that both fixer functions are present $args = func_get_args(); $callable = array_shift($args); return call_user_func_array_fixed($callable, $args); } function call_user_func_array_fixed($callable, $args) { var_dump(debug_backtrace(false)); $isStaticMethod = false; // Normalize the $callable and see if it looks like a static method if (is_object($callable) && $callable instanceof Closure) { $func = $callable; } else if (is_string($callable)) { $expr = '/^([a-z_\x7f-\xff][\w\x7f-\xff]*)::([a-z_\x7f-\xff][\w\x7f-\xff]*)$/i'; if (preg_match($expr, $callable, $matches)) { $func = array($matches[1], $matches[2]); $isStaticMethod = true; } else { $func = $callable; } } else if (is_array($callable) && isset($callable[0], $callable[1]) && count($callable) === 2) { if (is_object($callable[0])) { $func = $callable; } else if (is_string($callable[0])) { $func = $callable; $isStaticMethod = true; } } // If it's not a valid callable give up here if (!isset($callable) || (!$isStaticMethod && !is_callable($callable))) { trigger_error('call_user_func() expects parameter 1 to be a valid callback', E_USER_WARNING); return null; } // If it's not a static method use the regular mechanism if (!$isStaticMethod) { return call_user_func_array($func, $args); } // Get a reference to the static method if possible try { $class = new ReflectionClass($func[0]); $method = $class->getMethod($func[1]); } catch (ReflectionException $e) { trigger_error('call_user_func() expects parameter 1 to be a valid callback', E_USER_WARNING); return null; } // Invoke the method with the passed arguments and return the result return $method->invokeArgs(null, $args); } class Car { public function run() { return call_user_func_fixed('Toyota::getName'); // should call toyota } private static function getName() { return 'Car'; } } class Toyota extends Car { public static function getName() { return 'Toyota'; } } $car = new Car(); echo $car->run(); //Car instead of Toyota $toyota = new Toyota(); echo $toyota->run(); //Car instead of Toyota
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  (null)
number of ops:  13
compiled vars:  !0 = $car, !1 = $toyota
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   NEW                                              $2      'Car'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   77     3        INIT_METHOD_CALL                                         !0, 'run'
          4        DO_FCALL                                      0  $5      
          5        ECHO                                                     $5
   79     6        NEW                                              $6      'Toyota'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   80     9        INIT_METHOD_CALL                                         !1, 'run'
         10        DO_FCALL                                      0  $9      
         11        ECHO                                                     $9
         12      > RETURN                                                   1

Function call_user_func_fixed:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  call_user_func_fixed
number of ops:  12
compiled vars:  !0 = $args, !1 = $callable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   FUNC_GET_ARGS                                    ~2      
          1        ASSIGN                                                   !0, ~2
    7     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
    9     6        INIT_FCALL_BY_NAME                                       'call_user_func_array_fixed'
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $6      
         10      > RETURN                                                   $6
   10    11*     > RETURN                                                   null

End of function call_user_func_fixed

Function call_user_func_array_fixed:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
2 jumps found. (Code = 47) Position 1 = 59, Position 2 = 67
Branch analysis from position: 59
2 jumps found. (Code = 46) Position 1 = 61, Position 2 = 66
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 73
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 80
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 99
Branch analysis from position: 99
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
Branch analysis from position: 67
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 34
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 34
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 41
Branch analysis from position: 36
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 56
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
2 jumps found. (Code = 47) Position 1 = 59, Position 2 = 67
Branch analysis from position: 59
Branch analysis from position: 67
Branch analysis from position: 56
Branch analysis from position: 56
Branch analysis from position: 45
Branch analysis from position: 40
Branch analysis from position: 41
Branch analysis from position: 13
Found catch point at position: 93
Branch analysis from position: 93
2 jumps found. (Code = 107) Position 1 = 94, Position 2 = -2
Branch analysis from position: 94
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  call_user_func_array_fixed
number of ops:  105
compiled vars:  !0 = $callable, !1 = $args, !2 = $isStaticMethod, !3 = $func, !4 = $expr, !5 = $matches, !6 = $class, !7 = $method, !8 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'debug_backtrace'
          4        SEND_VAL                                                 <false>
          5        DO_ICALL                                         $9      
          6        SEND_VAR                                                 $9
          7        DO_ICALL                                                 
   15     8        ASSIGN                                                   !2, <false>
   18     9        TYPE_CHECK                                  256  ~12     !0
         10      > JMPZ_EX                                          ~12     ~12, ->13
         11    >   INSTANCEOF                                       ~13     !0, 'Closure'
         12        BOOL                                             ~12     ~13
         13    > > JMPZ                                                     ~12, ->16
   19    14    >   ASSIGN                                                   !3, !0
         15      > JMP                                                      ->56
   20    16    >   TYPE_CHECK                                   64          !0
         17      > JMPZ                                                     ~15, ->34
   21    18    >   ASSIGN                                                   !4, '%2F%5E%28%5Ba-z_%5Cx7f-%5Cxff%5D%5B%5Cw%5Cx7f-%5Cxff%5D%2A%29%3A%3A%28%5Ba-z_%5Cx7f-%5Cxff%5D%5B%5Cw%5Cx7f-%5Cxff%5D%2A%29%24%2Fi'
   22    19        INIT_FCALL                                               'preg_match'
         20        SEND_VAR                                                 !4
         21        SEND_VAR                                                 !0
         22        SEND_REF                                                 !5
         23        DO_ICALL                                         $17     
         24      > JMPZ                                                     $17, ->32
   23    25    >   FETCH_DIM_R                                      ~18     !5, 1
         26        INIT_ARRAY                                       ~19     ~18
         27        FETCH_DIM_R                                      ~20     !5, 2
         28        ADD_ARRAY_ELEMENT                                ~19     ~20
         29        ASSIGN                                                   !3, ~19
   24    30        ASSIGN                                                   !2, <true>
         31      > JMP                                                      ->33
   26    32    >   ASSIGN                                                   !3, !0
         33    > > JMP                                                      ->56
   28    34    >   TYPE_CHECK                                  128  ~24     !0
         35      > JMPZ_EX                                          ~24     ~24, ->41
         36    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~25     !0, 0
         37      > JMPZ_EX                                          ~25     ~25, ->40
         38    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~26     !0, 1
         39        BOOL                                             ~25     ~26
         40    >   BOOL                                             ~24     ~25
         41    > > JMPZ_EX                                          ~24     ~24, ->45
         42    >   COUNT                                            ~27     !0
         43        IS_IDENTICAL                                     ~28     ~27, 2
         44        BOOL                                             ~24     ~28
         45    > > JMPZ                                                     ~24, ->56
   29    46    >   FETCH_DIM_R                                      ~29     !0, 0
         47        TYPE_CHECK                                  256          ~29
         48      > JMPZ                                                     ~30, ->51
   30    49    >   ASSIGN                                                   !3, !0
         50      > JMP                                                      ->56
   31    51    >   FETCH_DIM_R                                      ~32     !0, 0
         52        TYPE_CHECK                                   64          ~32
         53      > JMPZ                                                     ~33, ->56
   32    54    >   ASSIGN                                                   !3, !0
   33    55        ASSIGN                                                   !2, <true>
   38    56    >   ISSET_ISEMPTY_CV                                 ~36     !0
         57        BOOL_NOT                                         ~37     ~36
         58      > JMPNZ_EX                                         ~37     ~37, ->67
         59    >   BOOL_NOT                                         ~38     !2
         60      > JMPZ_EX                                          ~38     ~38, ->66
         61    >   INIT_FCALL                                               'is_callable'
         62        SEND_VAR                                                 !0
         63        DO_ICALL                                         $39     
         64        BOOL_NOT                                         ~40     $39
         65        BOOL                                             ~38     ~40
         66    >   BOOL                                             ~37     ~38
         67    > > JMPZ                                                     ~37, ->73
   39    68    >   INIT_FCALL                                               'trigger_error'
         69        SEND_VAL                                                 'call_user_func%28%29+expects+parameter+1+to+be+a+valid+callback'
         70        SEND_VAL                                                 512
         71        DO_ICALL                                                 
   40    72      > RETURN                                                   null
   44    73    >   BOOL_NOT                                         ~42     !2
         74      > JMPZ                                                     ~42, ->80
   45    75    >   INIT_USER_CALL                                0          'call_user_func_array', !3
         76        SEND_ARRAY                                               !1
         77        CHECK_UNDEF_ARGS                                         
         78        DO_FCALL                                      0  $43     
         79      > RETURN                                                   $43
   50    80    >   NEW                                              $44     'ReflectionClass'
         81        CHECK_FUNC_ARG                                           
         82        FETCH_DIM_FUNC_ARG                               $45     !3, 0
         83        SEND_FUNC_ARG                                            $45
         84        DO_FCALL                                      0          
         85        ASSIGN                                                   !6, $44
   51    86        INIT_METHOD_CALL                                         !6, 'getMethod'
         87        CHECK_FUNC_ARG                                           
         88        FETCH_DIM_FUNC_ARG                               $48     !3, 1
         89        SEND_FUNC_ARG                                            $48
         90        DO_FCALL                                      0  $49     
         91        ASSIGN                                                   !7, $49
         92      > JMP                                                      ->99
   52    93  E > > CATCH                                       last         'ReflectionException'
   53    94    >   INIT_FCALL                                               'trigger_error'
         95        SEND_VAL                                                 'call_user_func%28%29+expects+parameter+1+to+be+a+valid+callback'
         96        SEND_VAL                                                 512
         97        DO_ICALL                                                 
   54    98      > RETURN                                                   null
   58    99    >   INIT_METHOD_CALL                                         !7, 'invokeArgs'
        100        SEND_VAL_EX                                              null
        101        SEND_VAR_EX                                              !1
        102        DO_FCALL                                      0  $52     
        103      > RETURN                                                   $52
   59   104*     > RETURN                                                   null

End of function call_user_func_array_fixed

Class Car:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  run
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_FCALL                                               'call_user_func_fixed'
          1        SEND_VAL                                                 'Toyota%3A%3AgetName'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   64     4*     > RETURN                                                   null

End of function run

Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  getName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E > > RETURN                                                   'Car'
   67     1*     > RETURN                                                   null

End of function getname

End of class Car.

Class Toyota:
Function getname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  getName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E > > RETURN                                                   'Toyota'
   73     1*     > RETURN                                                   null

End of function getname

Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R67ZF
function name:  run
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   INIT_FCALL                                               'call_user_func_fixed'
          1        SEND_VAL                                                 'Toyota%3A%3AgetName'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   64     4*     > RETURN                                                   null

End of function run

End of class Toyota.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.45 ms | 1415 KiB | 27 Q