ReflectionClass::getDefaultProperties

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getDefaultProperties获取默认属性

说明

public ReflectionClass::getDefaultProperties(): array

获取类的默认属性(包括了继承的属性)。

注意:

当在内部类中使用时,此方法仅用于静态属性,当在用户定义类中使用此方法时,无法追踪静态类属性的默认值。

参数

此函数没有参数。

返回值

默认属性的 array,其键是属性的名称,其值是属性的默认值或者 null(如果没有默认值)。这个函数不区分静态和非静态属性,也不考虑可见性修饰符。

范例

示例 #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"
}

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top