Home  >  Article  >  Backend Development  >  php怎么判断成员函数的访问权限是public

php怎么判断成员函数的访问权限是public

WBOY
WBOYOriginal
2016-06-13 13:28:07945browse

php如何判断成员函数的访问权限是public
class test{
  public function aaa(){
  echo 'aaat';
  }

  protected function bbb(){
  echo 'bbb';
  }

  private function ccc(){
  echo 'ccc';
  }
}

如何判断 test 这个类 aaa,bbb,ccc 成员函数 是属于 public或protected或private 的访问权限。
请给为大侠解答。
分送上。

------解决方案--------------------
stackoverflow上面找到的方法

PHP code
<?php class Test{
    public function foo(){}
    
    private function bar(){}
}
$foo = new ReflectionMethod('Test', 'foo');
$s=Reflection::getModifierNames($foo->getModifiers());
print_r($s);

$foo = new ReflectionMethod('Test', 'bar');
$s=Reflection::getModifierNames($foo->getModifiers());
print_r($s);
<br><font color="#e78608">------解决方案--------------------</font><br>http://cn.php.net/manual/en/class.reflectionmethod.php
<br><font color="#e78608">------解决方案--------------------</font><br>反射的典型应用
<br><font color="#e78608">------解决方案--------------------</font><br>http://www.php.net/manual/en/reflectionmethod.construct.php<br><br>一看就是反射,翻了翻就找到了这个。 <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn