3v4l.org

run code in 300+ PHP versions simultaneously
<?php function call_user_func_fixed() { $args = func_get_args(); $callable = array_shift($args); call_user_func_array_fixed($callable, $args); } function call_user_func_array_fixed($callable, $args) { $isStaticMethod = false; if (is_object($callable) && $callable instanceof Closure) { $func = $callable; } else if (is_string($callable)) { if (preg_match('/^([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)::([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$/', $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 (!isset($callable) || !is_callable($callable)) { trigger_error('call_user_func() expects parameter 1 to be a valid callback', E_USER_WARNING); return null; } if (!$isStaticMethod) { return call_user_func_array($func, $args); } 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; } 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/k7SYq
function name:  (null)
number of ops:  13
compiled vars:  !0 = $car, !1 = $toyota
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   67     0  E >   NEW                                              $2      'Car'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   68     3        INIT_METHOD_CALL                                         !0, 'run'
          4        DO_FCALL                                      0  $5      
          5        ECHO                                                     $5
   70     6        NEW                                              $6      'Toyota'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   71     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/k7SYq
function name:  call_user_func_fixed
number of ops:  11
compiled vars:  !0 = $args, !1 = $callable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FUNC_GET_ARGS                                    ~2      
          1        ASSIGN                                                   !0, ~2
    6     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
    7     6        INIT_FCALL_BY_NAME                                       'call_user_func_array_fixed'
          7        SEND_VAR_EX                                              !1
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0          
    8    10      > 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 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 47) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 63
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 70
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 89
Branch analysis from position: 89
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 27
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 49
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 49
Branch analysis from position: 47
2 jumps found. (Code = 47) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
Branch analysis from position: 57
Branch analysis from position: 49
Branch analysis from position: 49
Branch analysis from position: 38
Branch analysis from position: 33
Branch analysis from position: 34
Branch analysis from position: 7
Found catch point at position: 83
Branch analysis from position: 83
2 jumps found. (Code = 107) Position 1 = 84, Position 2 = -2
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k7SYq
function name:  call_user_func_array_fixed
number of ops:  95
compiled vars:  !0 = $callable, !1 = $args, !2 = $isStaticMethod, !3 = $func, !4 = $matches, !5 = $class, !6 = $method, !7 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN                                                   !2, <false>
   14     3        TYPE_CHECK                                  256  ~9      !0
          4      > JMPZ_EX                                          ~9      ~9, ->7
          5    >   INSTANCEOF                                       ~10     !0, 'Closure'
          6        BOOL                                             ~9      ~10
          7    > > JMPZ                                                     ~9, ->10
   15     8    >   ASSIGN                                                   !3, !0
          9      > JMP                                                      ->49
   16    10    >   TYPE_CHECK                                   64          !0
         11      > JMPZ                                                     ~12, ->27
   17    12    >   INIT_FCALL                                               'preg_match'
         13        SEND_VAL                                                 '%2F%5E%28%5Ba-zA-Z_%5Cx7f-%5Cxff%5D%5Ba-zA-Z0-9_%5Cx7f-%5Cxff%5D%2A%29%3A%3A%28%5Ba-zA-Z_%5Cx7f-%5Cxff%5D%5Ba-zA-Z0-9_%5Cx7f-%5Cxff%5D%2A%29%24%2F'
         14        SEND_VAR                                                 !0
         15        SEND_REF                                                 !4
         16        DO_ICALL                                         $13     
         17      > JMPZ                                                     $13, ->25
   18    18    >   FETCH_DIM_R                                      ~14     !4, 1
         19        INIT_ARRAY                                       ~15     ~14
         20        FETCH_DIM_R                                      ~16     !4, 2
         21        ADD_ARRAY_ELEMENT                                ~15     ~16
         22        ASSIGN                                                   !3, ~15
   19    23        ASSIGN                                                   !2, <true>
         24      > JMP                                                      ->26
   21    25    >   ASSIGN                                                   !3, !0
         26    > > JMP                                                      ->49
   23    27    >   TYPE_CHECK                                  128  ~20     !0
         28      > JMPZ_EX                                          ~20     ~20, ->34
         29    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~21     !0, 0
         30      > JMPZ_EX                                          ~21     ~21, ->33
         31    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~22     !0, 1
         32        BOOL                                             ~21     ~22
         33    >   BOOL                                             ~20     ~21
         34    > > JMPZ_EX                                          ~20     ~20, ->38
         35    >   COUNT                                            ~23     !0
         36        IS_IDENTICAL                                     ~24     ~23, 2
         37        BOOL                                             ~20     ~24
         38    > > JMPZ                                                     ~20, ->49
   24    39    >   FETCH_DIM_R                                      ~25     !0, 0
         40        TYPE_CHECK                                  256          ~25
         41      > JMPZ                                                     ~26, ->44
   25    42    >   ASSIGN                                                   !3, !0
         43      > JMP                                                      ->49
   26    44    >   FETCH_DIM_R                                      ~28     !0, 0
         45        TYPE_CHECK                                   64          ~28
         46      > JMPZ                                                     ~29, ->49
   27    47    >   ASSIGN                                                   !3, !0
   28    48        ASSIGN                                                   !2, <true>
   32    49    >   ISSET_ISEMPTY_CV                                 ~32     !0
         50        BOOL_NOT                                         ~33     ~32
         51      > JMPNZ_EX                                         ~33     ~33, ->57
         52    >   INIT_FCALL                                               'is_callable'
         53        SEND_VAR                                                 !0
         54        DO_ICALL                                         $34     
         55        BOOL_NOT                                         ~35     $34
         56        BOOL                                             ~33     ~35
         57    > > JMPZ                                                     ~33, ->63
   33    58    >   INIT_FCALL                                               'trigger_error'
         59        SEND_VAL                                                 'call_user_func%28%29+expects+parameter+1+to+be+a+valid+callback'
         60        SEND_VAL                                                 512
         61        DO_ICALL                                                 
   34    62      > RETURN                                                   null
   37    63    >   BOOL_NOT                                         ~37     !2
         64      > JMPZ                                                     ~37, ->70
   38    65    >   INIT_USER_CALL                                0          'call_user_func_array', !3
         66        SEND_ARRAY                                               !1
         67        CHECK_UNDEF_ARGS                                         
         68        DO_FCALL                                      0  $38     
         69      > RETURN                                                   $38
   42    70    >   NEW                                              $39     'ReflectionClass'
         71        CHECK_FUNC_ARG                                           
         72        FETCH_DIM_FUNC_ARG                               $40     !3, 0
         73        SEND_FUNC_ARG                                            $40
         74        DO_FCALL                                      0          
         75        ASSIGN                                                   !5, $39
   43    76        INIT_METHOD_CALL                                         !5, 'getMethod'
         77        CHECK_FUNC_ARG                                           
         78        FETCH_DIM_FUNC_ARG                               $43     !3, 1
         79        SEND_FUNC_ARG                                            $43
         80        DO_FCALL                                      0  $44     
         81        ASSIGN                                                   !6, $44
         82      > JMP                                                      ->89
   44    83  E > > CATCH                                       last         'ReflectionException'
   45    84    >   INIT_FCALL                                               'trigger_error'
         85        SEND_VAL                                                 'call_user_func%28%29+expects+parameter+1+to+be+a+valid+callback'
         86        SEND_VAL                                                 512
         87        DO_ICALL                                                 
   46    88      > RETURN                                                   null
   49    89    >   INIT_METHOD_CALL                                         !6, 'invokeArgs'
         90        SEND_VAL_EX                                              null
         91        SEND_VAR_EX                                              !1
         92        DO_FCALL                                      0  $47     
         93      > RETURN                                                   $47
   50    94*     > 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/k7SYq
function name:  run
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_FCALL                                               'call_user_func_fixed'
          1        SEND_VAL                                                 'Toyota%3A%3AgetName'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   55     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/k7SYq
function name:  getName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E > > RETURN                                                   'Car'
   58     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/k7SYq
function name:  getName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E > > RETURN                                                   'Toyota'
   64     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/k7SYq
function name:  run
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   54     0  E >   INIT_FCALL                                               'call_user_func_fixed'
          1        SEND_VAL                                                 'Toyota%3A%3AgetName'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   55     4*     > RETURN                                                   null

End of function run

End of class Toyota.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.3 ms | 1415 KiB | 23 Q