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

End of function run

End of class Toyota.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.36 ms | 1415 KiB | 23 Q