假设我有班级:
class MyClass {
protected $protected;
private $_private;
public function __get($name) {
return $this->{$name};
}
}
我想“神奇地”获取受保护的变量,但不是私有变量。是否有内置的PHP函数可以帮助我识别类变量的可见性?
答案 0 :(得分:2)
$refClass = new ReflectionClass('MyClass');
foreach ($refClass->getProperties() as $property) {
if ($property->isProtected()) echo $property->getName();
}