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 target static method if possible try { if (!strcasecmp($func[0], 'self')) { $backtrace = debug_backtrace(); // passing args here is fraught with complications for backwards compat :-( $key = $backtrace[1]['function'] === 'call_user_func_fixed' ? 2 : 1; if (empty($backtrace[$key]['class'])) { trigger_error('call_user_func() expects parameter 1 to be a valid callback', E_USER_WARNING); return null; } $class = new ReflectionClass($backtrace[$key]['class']); // I know this looks odd, but it's what self:: does $method = $class->getMethod($func[1])->getDeclaringClass()->getMethod($func[1]); } else if (function_exists('get_called_class') && !strcasecmp($func[0], 'static')) { $class = new ReflectionClass(get_called_class()); $method = $class->getMethod($func[1]); } else { $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('self::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/Yl2q2
function name:  (null)
number of ops:  13
compiled vars:  !0 = $car, !1 = $toyota
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   92     0  E >   NEW                                              $2      'Car'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   93     3        INIT_METHOD_CALL                                         !0, 'run'
          4        DO_FCALL                                      0  $5      
          5        ECHO                                                     $5
   95     6        NEW                                              $6      'Toyota'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   96     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/Yl2q2
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
2 jumps found. (Code = 43) Position 1 = 81, Position 2 = 121
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 90
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 100
Branch analysis from position: 95
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
1 jumps found. (Code = 42) Position 1 = 157
Branch analysis from position: 157
1 jumps found. (Code = 42) Position 1 = 164
Branch analysis from position: 164
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 100
Branch analysis from position: 95
Branch analysis from position: 100
Branch analysis from position: 121
2 jumps found. (Code = 46) Position 1 = 125, Position 2 = 132
Branch analysis from position: 125
2 jumps found. (Code = 43) Position 1 = 133, Position 2 = 145
Branch analysis from position: 133
1 jumps found. (Code = 42) Position 1 = 157
Branch analysis from position: 157
Branch analysis from position: 145
1 jumps found. (Code = 42) Position 1 = 164
Branch analysis from position: 164
Branch analysis from position: 132
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: 158
Branch analysis from position: 158
2 jumps found. (Code = 107) Position 1 = 159, Position 2 = -2
Branch analysis from position: 159
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yl2q2
function name:  call_user_func_array_fixed
number of ops:  170
compiled vars:  !0 = $callable, !1 = $args, !2 = $isStaticMethod, !3 = $func, !4 = $expr, !5 = $matches, !6 = $backtrace, !7 = $key, !8 = $class, !9 = $method, !10 = $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  ~12     !0
          4      > JMPZ_EX                                          ~12     ~12, ->7
          5    >   INSTANCEOF                                       ~13     !0, 'Closure'
          6        BOOL                                             ~12     ~13
          7    > > JMPZ                                                     ~12, ->10
   18     8    >   ASSIGN                                                   !3, !0
          9      > JMP                                                      ->50
   19    10    >   TYPE_CHECK                                   64          !0
         11      > JMPZ                                                     ~15, ->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                                         $17     
         18      > JMPZ                                                     $17, ->26
   22    19    >   FETCH_DIM_R                                      ~18     !5, 1
         20        INIT_ARRAY                                       ~19     ~18
         21        FETCH_DIM_R                                      ~20     !5, 2
         22        ADD_ARRAY_ELEMENT                                ~19     ~20
         23        ASSIGN                                                   !3, ~19
   23    24        ASSIGN                                                   !2, <true>
         25      > JMP                                                      ->27
   25    26    >   ASSIGN                                                   !3, !0
         27    > > JMP                                                      ->50
   27    28    >   TYPE_CHECK                                  128  ~24     !0
         29      > JMPZ_EX                                          ~24     ~24, ->35
         30    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~25     !0, 0
         31      > JMPZ_EX                                          ~25     ~25, ->34
         32    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~26     !0, 1
         33        BOOL                                             ~25     ~26
         34    >   BOOL                                             ~24     ~25
         35    > > JMPZ_EX                                          ~24     ~24, ->39
         36    >   COUNT                                            ~27     !0
         37        IS_IDENTICAL                                     ~28     ~27, 2
         38        BOOL                                             ~24     ~28
         39    > > JMPZ                                                     ~24, ->50
   28    40    >   FETCH_DIM_R                                      ~29     !0, 0
         41        TYPE_CHECK                                  256          ~29
         42      > JMPZ                                                     ~30, ->45
   29    43    >   ASSIGN                                                   !3, !0
         44      > JMP                                                      ->50
   30    45    >   FETCH_DIM_R                                      ~32     !0, 0
         46        TYPE_CHECK                                   64          ~32
         47      > JMPZ                                                     ~33, ->50
   31    48    >   ASSIGN                                                   !3, !0
   32    49        ASSIGN                                                   !2, <true>
   37    50    >   ISSET_ISEMPTY_CV                                 ~36     !0
         51        BOOL_NOT                                         ~37     ~36
         52      > JMPNZ_EX                                         ~37     ~37, ->61
         53    >   BOOL_NOT                                         ~38     !2
         54      > JMPZ_EX                                          ~38     ~38, ->60
         55    >   INIT_FCALL                                               'is_callable'
         56        SEND_VAR                                                 !0
         57        DO_ICALL                                         $39     
         58        BOOL_NOT                                         ~40     $39
         59        BOOL                                             ~38     ~40
         60    >   BOOL                                             ~37     ~38
         61    > > JMPZ                                                     ~37, ->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                                         ~42     !2
         68      > JMPZ                                                     ~42, ->74
   44    69    >   INIT_USER_CALL                                0          'call_user_func_array', !3
         70        SEND_ARRAY                                               !1
         71        CHECK_UNDEF_ARGS                                         
         72        DO_FCALL                                      0  $43     
         73      > RETURN                                                   $43
   49    74    >   INIT_FCALL                                               'strcasecmp'
         75        FETCH_DIM_R                                      ~44     !3, 0
         76        SEND_VAL                                                 ~44
         77        SEND_VAL                                                 'self'
         78        DO_ICALL                                         $45     
         79        BOOL_NOT                                         ~46     $45
         80      > JMPZ                                                     ~46, ->121
   50    81    >   INIT_FCALL                                               'debug_backtrace'
         82        DO_ICALL                                         $47     
         83        ASSIGN                                                   !6, $47
   51    84        FETCH_DIM_R                                      ~49     !6, 1
         85        FETCH_DIM_R                                      ~50     ~49, 'function'
         86        IS_IDENTICAL                                             ~50, 'call_user_func_fixed'
         87      > JMPZ                                                     ~51, ->90
         88    >   QM_ASSIGN                                        ~52     2
         89      > JMP                                                      ->91
         90    >   QM_ASSIGN                                        ~52     1
         91    >   ASSIGN                                                   !7, ~52
   53    92        FETCH_DIM_IS                                     ~54     !6, !7
         93        ISSET_ISEMPTY_DIM_OBJ                         1          ~54, 'class'
         94      > JMPZ                                                     ~55, ->100
   54    95    >   INIT_FCALL                                               'trigger_error'
         96        SEND_VAL                                                 'call_user_func%28%29+expects+parameter+1+to+be+a+valid+callback'
         97        SEND_VAL                                                 512
         98        DO_ICALL                                                 
   55    99      > RETURN                                                   null
   58   100    >   NEW                                              $57     'ReflectionClass'
        101        CHECK_FUNC_ARG                                           
        102        FETCH_DIM_FUNC_ARG                               $58     !6, !7
        103        FETCH_DIM_FUNC_ARG                               $59     $58, 'class'
        104        SEND_FUNC_ARG                                            $59
        105        DO_FCALL                                      0          
        106        ASSIGN                                                   !8, $57
   60   107        INIT_METHOD_CALL                                         !8, 'getMethod'
        108        CHECK_FUNC_ARG                                           
        109        FETCH_DIM_FUNC_ARG                               $62     !3, 1
        110        SEND_FUNC_ARG                                            $62
        111        DO_FCALL                                      0  $63     
        112        INIT_METHOD_CALL                                         $63, 'getDeclaringClass'
        113        DO_FCALL                                      0  $64     
        114        INIT_METHOD_CALL                                         $64, 'getMethod'
        115        CHECK_FUNC_ARG                                           
        116        FETCH_DIM_FUNC_ARG                               $65     !3, 1
        117        SEND_FUNC_ARG                                            $65
        118        DO_FCALL                                      0  $66     
        119        ASSIGN                                                   !9, $66
        120      > JMP                                                      ->157
   61   121    >   INIT_FCALL                                               'function_exists'
        122        SEND_VAL                                                 'get_called_class'
        123        DO_ICALL                                         $68     
        124      > JMPZ_EX                                          ~69     $68, ->132
        125    >   INIT_FCALL                                               'strcasecmp'
        126        FETCH_DIM_R                                      ~70     !3, 0
        127        SEND_VAL                                                 ~70
        128        SEND_VAL                                                 'static'
        129        DO_ICALL                                         $71     
        130        BOOL_NOT                                         ~72     $71
        131        BOOL                                             ~69     ~72
        132    > > JMPZ                                                     ~69, ->145
   62   133    >   NEW                                              $73     'ReflectionClass'
        134        GET_CALLED_CLASS                                 ~74     
        135        SEND_VAL_EX                                              ~74
        136        DO_FCALL                                      0          
        137        ASSIGN                                                   !8, $73
   63   138        INIT_METHOD_CALL                                         !8, 'getMethod'
        139        CHECK_FUNC_ARG                                           
        140        FETCH_DIM_FUNC_ARG                               $77     !3, 1
        141        SEND_FUNC_ARG                                            $77
        142        DO_FCALL                                      0  $78     
        143        ASSIGN                                                   !9, $78
        144      > JMP                                                      ->157
   65   145    >   NEW                                              $80     'ReflectionClass'
        146        CHECK_FUNC_ARG                                           
        147        FETCH_DIM_FUNC_ARG                               $81     !3, 0
        148        SEND_FUNC_ARG                                            $81
        149        DO_FCALL                                      0          
        150        ASSIGN                                                   !8, $80
   66   151        INIT_METHOD_CALL                                         !8, 'getMethod'
        152        CHECK_FUNC_ARG                                           
        153        FETCH_DIM_FUNC_ARG                               $84     !3, 1
        154        SEND_FUNC_ARG                                            $84
        155        DO_FCALL                                      0  $85     
        156        ASSIGN                                                   !9, $85
        157    > > JMP                                                      ->164
   68   158  E > > CATCH                                       last         'ReflectionException'
   69   159    >   INIT_FCALL                                               'trigger_error'
        160        SEND_VAL                                                 'call_user_func%28%29+expects+parameter+1+to+be+a+valid+callback'
        161        SEND_VAL                                                 512
        162        DO_ICALL                                                 
   70   163      > RETURN                                                   null
   74   164    >   INIT_METHOD_CALL                                         !9, 'invokeArgs'
        165        SEND_VAL_EX                                              null
        166        SEND_VAR_EX                                              !1
        167        DO_FCALL                                      0  $88     
        168      > RETURN                                                   $88
   75   169*     > 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/Yl2q2
function name:  run
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_FCALL                                               'call_user_func_fixed'
          1        SEND_VAL                                                 'self%3A%3AgetName'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   80     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/Yl2q2
function name:  getName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E > > RETURN                                                   'Car'
   83     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/Yl2q2
function name:  getName
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   88     0  E > > RETURN                                                   'Toyota'
   89     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/Yl2q2
function name:  run
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_FCALL                                               'call_user_func_fixed'
          1        SEND_VAL                                                 'self%3A%3AgetName'
          2        DO_FCALL                                      0  $0      
          3      > RETURN                                                   $0
   80     4*     > RETURN                                                   null

End of function run

End of class Toyota.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.79 ms | 961 KiB | 31 Q