S
S
scottparker2020-05-06 19:11:39
PHP
scottparker, 2020-05-06 19:11:39

Is it possible to determine if a method is static or not?

Good evening.
There is some class with a set of static and normal methods.

class MyClass
{
    public static function methodA(){
       ...
    }
    public function methodB(){
       ...
    }
}


There is an array with the name of the class and the name of the method (static or not, we do not know), for example,
$data = [
  "class"=>  "MyClass",
  "method"=> "methodA"
];

You need to call the methodA method without knowing whether it is static or not.
Is it possible to determine which method methodA is? (or is there another solution to this problem?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-05-06
@scottparker

(new ReflectionMethod('MyClass', 'methodA'))->isStatic();

Well, in general, why do you need to know if a method is static or not? Static is called without context, NOT statically with context, i.e. on a good call should be:
call_user_func([$object, 'method']);
call_user_func(['ClassName', 'staticMethod']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question