(PHP 5, PHP 7, PHP 8)
ReflectionClass::getDefaultProperties — 獲取默認(rèn)屬性
獲取類的默認(rèn)屬性(包括了繼承的屬性)。
注意:
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.
此函數(shù)沒有參數(shù)。
默認(rèn)屬性的數(shù)組,其鍵是屬性的名稱,其值是屬性的默認(rèn)值或者在屬性沒有默認(rèn)值時(shí)是 null。
這個(gè)函數(shù)不區(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());
?>
以上例程會(huì)輸出:
array(5) {
["staticProperty"]=>
string(14) "staticProperty"
["property"]=>
string(15) "propertyDefault"
["privateProperty"]=>
string(22) "privatePropertyDefault"
["defaultlessProperty"]=>
NULL
["inheritedProperty"]=>
string(16) "inheritedDefault"
}