ReflectionClass
PHP Manual

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
PHP Manual