Reputation: 68406
I have a function that takes a "callback" argument. This can be either a function or a static class method.
How can I detect if the method is static or not?
Upvotes: 0
Views: 95
Reputation: 237837
I suppose you could do this with reflection, though this will be slow.
Presuming your callback is $callback
:
if (is_array($callback)) { // a function will just be a string
$classname = $callback[0];
$methodname = $callback[1];
$method = new ReflectionMethod($classname, $methodname);
if ($method->isStatic()) {
// method is static
}
}
Note that this doesn't account for times when $callback[0]
is an object, or if you have a lambda function as $callback
, or probably all kinds of different circumstances. I don't really understand what you're looking for; this may be sufficient.
Upvotes: 2