【问题标题】:How to check whether a method is static in PHP?如何检查PHP中的方法是否是静态的?
【发布时间】:2011-11-22 17:41:52
【问题描述】:

我需要知道该方法是否被声明为静态给定它的名称和包含它的类的名称。 method_exists 为静态和非静态方法提供true

【问题讨论】:

    标签: php methods static


    【解决方案1】:

    下面是关于如何使用 ReflectionMethod 的更清晰的方法:

    $MethodChecker = new ReflectionMethod($ClassName,$MethodName);
    var_dump($MethodChecker->isStatic());
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 这是如何工作的?该链接指向 ReflectionClass::getStaticPropertyValue 但这是针对属性而不是方法的。它应该链接在这里:php.net/manual/en/reflectionmethod.isstatic.php 但它没有示例,我无法弄清楚它是如何工作的。
      • 想通了。添加新答案。
      • $method = new ReflectionMethod ('NameOfClass', 'nameOfMethod'); $isStatic = $method->isStatic();
      猜你喜欢
      • 2012-12-20
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      • 2021-05-12
      • 1970-01-01
      相关资源
      最近更新 更多