(PHP 5, PHP 7, PHP 8)
ReflectionClass::getDefaultProperties — 獲取默認屬性
獲取類的默認屬性(包括了繼承的屬性)。
注意:
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。
這個函數不區(qū)分靜態(tài)和非靜態(tài)屬性,也不考慮可見性修飾符。
示例 #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"
}