Worth noting that it will not return private parameters of parent class...
so it works exactly as get_class_vars or get_object_vars
ReflectionClass::getDefaultProperties
(PHP 5)
ReflectionClass::getDefaultProperties — 获取默认属性
说明
public array ReflectionClass::getDefaultProperties
( void
)
获取类的默认属性(包括了继承的属性)。
参数
此函数没有参数。
返回值
默认属性的数组,其键是属性的名称,其值是属性的默认值或者在属性没有默认值时是 NULL。
这个函数不区分静态和非静态属性,也不考虑可见性修饰符。
范例
Example #1 ReflectionClass::getDefaultProperties() 例子
<?php
class Bar {
protected $inheritedProperty = 'inheritedDefault';
}
class Foo extends Bar {
public $property = 'propertyDefault';
private $privateProperty = 'privatePropertyDefault';
public static $staticProperty = 'staticProperty';
public $defaultlessProperty;
}
$reflectionClass = new ReflectionClass('Foo');
var_dump($reflectionClass->getDefaultProperties());
?>
以上例程会输出:
array(5) {
["staticProperty"]=>
string(14) "staticProperty"
["property"]=>
string(15) "propertyDefault"
["privateProperty"]=>
string(22) "privatePropertyDefault"
["defaultlessProperty"]=>
NULL
["inheritedProperty"]=>
string(16) "inheritedDefault"
}
参见
- ReflectionClass::getProperties() - 获取一组属性
- ReflectionClass::getStaticProperties() - 获取静态(static)属性
- ReflectionClass::getProperty() - 获取类的一个属性的 ReflectionProperty
runaurufu AT gmail.com ¶
1 year ago
captainjester at hotmail dot com ¶
3 years ago
This will return all properties in a class and any parent classes. The array will have keys set to the property names and empty values.
