I have two variables:
$a = 'some_class';
$b = 'some_method';
What I want to do is something like this (the method is static):
$a::$b;
Is it possible? I’ve tried the reflection class, but I can’t call static methods…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
How to invoke the static method, 3 options
You have a few options:
Code
Output
What happens when you call it with those options
Code with a backtrace so you can see what happens under the hood in PHP:
Code
Output
$class::$method($arg);
call_user_func(array($class, $method), $arg);
eval($command);
As you can see first way has no step in between which is being registered, it directly makes the call while the other 2 options act by themselves as a function and make the call from themselves.
In practice not a lot of difference but it might make sense when optimizing such a process.