PHP ReflectionClass::getProperties 反射函数
Laiyong Wang Lv5

ReflectionProperty::IS_STATIC - 指示了 static 的属性。
ReflectionProperty::IS_PUBLIC - 指示了 public 的属性。
ReflectionProperty::IS_PROTECTED - 指示了 protected 的属性。
ReflectionProperty::IS_PRIVATE - 指示了 private 的属性。

ReflectionProperty::IS_PUBLIC 包含 ReflectionProperty::IS_STATIC

不知道是不是 bug 还是 static 就是公共的,的确可以随便访问

可以这样处理
1
2
3
4
5
6
7
$class = new ReflectionClass($this);
$names = [];
foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
if (!$property->isStatic()) {
$names[] = $property->getName();
}
}
 Comments