0
$this->categories = tx_dagoupost_lib::getCategories();

对于上面的代码:我怎样才能找到getCategories()声明为静态的wheather?因为我们也可以这样调用普通函数: tx_dagoupost_lib::getCategories();,虽然它不正确。似乎我可以使用这个:ReflectionMethod::isStatic,但我不知道如何使用它,这里没有示例:http: //php.net/manual/en/reflectionmethod.isstatic.php,所以任何人都可以告诉我如何检查是否getCategories()是静态函数。

4

3 回答 3

1

如果您查看文档的其余部分Reflection,您会发现这是获取ReflectionMethod对象的方式:

$class = new ReflectionClass('tx_dagoupost_lib');
$method = $class->getMethod('getCategories');
if ($method->isStatic()) {
    ...
}
于 2013-08-16T07:28:02.360 回答
1

你可以这样做:

$check_static = new ReflectionMethod('tx_dagoupost_lib', 'getCategories');

if( $check_static->isStatic() ) {
   echo "Its static method";
}
于 2013-08-16T07:28:08.493 回答
0

你可以使用这样的东西:

$methods = $class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_FINAL);
var_dump($methods);

查看更多详情

于 2013-08-16T07:30:51.473 回答