【发布时间】:2012-04-18 00:53:04
【问题描述】:
This thread 没有帮助我。
如果我使用
$class_vars = get_class_vars(get_class($this));
foreach ($class_vars as $name => $value) {
echo "$name : $value\n";
}
我明白了
attrib1_name:attrib2_name:attrib3_name
没有值。还显示了一个私有属性,这是我不想要的。
如果我使用
echo "<pre>";
print_r(get_object_vars($this));
echo "</pre>";
我明白了
数组 ( [attrib1_name] => attrib1_value [attrib2_name] => attrib2_value )
这里我又有一个私有属性和所有子属性。但这一次我有价值观。如何将其限制在一个级别?
是否有可能显示所有公共属性及其对象的值?
【问题讨论】:
-
私有属性会在您从私有 props 可见的范围内调用 get_class_vars 时显示。来自文档:
Depending on the scope, get_class_vars() will only return the properties that can be accessed from the current scope.
标签: php class object attributes