PHP:识别类变量的可见性

时间:2011-11-06 01:55:47

标签: php oop

假设我有班级:

class MyClass {

    protected $protected;
    private $_private;

    public function __get($name) {
        return $this->{$name};
    }

}

我想“神奇地”获取受保护的变量,但不是私有变量。是否有内置的PHP函数可以帮助我识别类变量的可见性?

1 个答案:

答案 0 :(得分:2)

$refClass = new ReflectionClass('MyClass');
foreach ($refClass->getProperties() as $property) {
  if ($property->isProtected()) echo $property->getName();
}