I just wrote a method with some extra functionality that expands on Daniel's answer.
It allows you to return static or object methods only.
It also allows you to only return methods that have been defined in that class.
Supply your own namespace or just copy the method.
Example Usage:
$methods = Reflection::getClassMethods(__CLASS__);
Code:
<?php
namespace [Your]\[Namespace];
class Reflection {
/**
* Return class methods by scope
*
* @param string $class
* @param bool $inherit
* @static bool|null $static returns static methods | object methods | both
* @param array $scope ['public', 'protected', 'private']
* @return array
*/
public static function getClassMethods($class, $inherit = false, $static = null, $scope = ['public', 'protected', 'private'])
{
$return = [
'public' => [],
'protected' => [],
'private' => []
];
$reflection = new \ReflectionClass($class);
foreach ($scope as $key) {
$pass = false;
switch ($key) {
case 'public': $pass = \ReflectionMethod::IS_PUBLIC;
break;
case 'protected': $pass = \ReflectionMethod::IS_PROTECTED;
break;
case 'private': $pass = \ReflectionMethod::IS_PRIVATE;
break;
}
if ($pass) {
$methods = $reflection->getMethods($pass);
foreach ($methods as $method) {
$isStatic = $method->isStatic();
if (!is_null($static) && $static && !$isStatic) {
continue;
} elseif (!is_null($static) && !$static && $isStatic) {
continue;
}
if (!$inherit && $method->class === $reflection->getName()) {
$return[$key][] = $method->name;
} elseif ($inherit) {
$return[$key][] = $method->name;
}
}
}
}
return $return;
}
}
$methods = array_filter($class->getMethods(ReflectionMethod::IS_PUBLIC), function ($o) use ($class) {return $o->class == $class->getName();});