©
Ce document utilise Manuel du site Web PHP chinois Libérer
(PHP 5)
ReflectionClass::getDefaultProperties — 获取默认属性
获取类的默认属性(包括了继承的属性)。
Note:
This method only works for static properties when used on internal classes. The default value of a static class property can not be tracked when using this method on user defined classes.
此函数没有参数。
默认属性的 数组 ,其键是属性的名称,其值是属性的默认值或者在属性没有默认值时是 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" }
[#1] runaurufu AT gmail.com [2011-08-04 01:02:30]
Worth noting that it will not return private parameters of parent class...
so it works exactly as get_class_vars or get_object_vars
[#2] captainjester at hotmail dot com [2010-01-20 15:20:17]
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.