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