i want to call a class method by a var (like this):
$var = "read";
$params = array(...); //some parameter
if(/* MyClass has the static method $var */)
{
echo MyClass::$var($params);
}
elseif (/* MyClass hat a non-static method $var */)
{
$cl = new MyClass($params);
echo $cl->$var();
}
else throw new Exception();
i read in the php-manual how to get the function-members of a class (get_class_methods). but i get always every member without information if its static or not.
how can i determine a method´s context?
thank you for your help
One way I know of is to use Reflection. In particular, one would use
ReflectionClass::getMethods
as such:The difficulty of this is that you need to have Reflection enabled, which it is not by default.
Use the class
ReflectionClass
:This will output all static functions.
Or if you want to determine whether a given function is static you can use the
ReflectionMethod
class:On Codepad.org: http://codepad.org/2YXE7NJb