I need to check if a class implements specific method and then call it. If a method exists and is static it should be called static, otherwise it should be invoked on a class instance (object). The problem occurs when determining if a method is defined within a class as a static method.
Here is an example code that tests specific instance or class for method existence.
class A {
public function b() {}
public static function c() {}
}
$instance = new A();
var_dump(method_exists('A', 'b'));
var_dump(method_exists($instance, 'b'));
var_dump(method_exists('A', 'c'));
var_dump(method_exists($instance, 'c'));
var_dump(is_callable(['A', 'b']));
var_dump(is_callable([$instance, 'b']));
var_dump(is_callable(['A', 'c']));
var_dump(is_callable([$instance, 'c']));
When executed the output is as following:
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
The question is why the result is always true even if the callable argument is passed for static or non static call?
How to test if a method is defined as static without using Reflection?