ReflectionProperty::getDefaultValue
(PHP 8)
ReflectionProperty::getDefaultValue — プロパティで宣言されたデフォルト値を返す
パラメータ
この関数にはパラメータはありません。
返り値
プロパティに何かしらデフォルト値が存在する場合(null
も含みます)、
それを返します。デフォルト値がない場合、null
を返します。
デフォルト値が null
の場合と、型付きプロパティが初期化されてない場合は区別できません。
それらを区別するには、ReflectionClass::hasDefaultValue() を使って下さい。
例
例1 ReflectionClass::getDefaultValue() の例
<?phpclass Foo { public $bar = 1; public ?int $baz; public int $boing = 0;}$ro = new ReflectionClass(Foo::class);var_dump($ro->getProperty('bar')->getDefaultValue());var_dump($ro->getProperty('baz')->getDefaultValue());var_dump($ro->getProperty('boing')->getDefaultValue());?>
上の例の出力は以下となります。
int(1) NULL int(0)