array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'reflectionproperty.isinitialized.php', 1 => 'ReflectionProperty::isInitialized', ), 'up' => array ( 0 => 'class.reflectionproperty.php', 1 => 'ReflectionProperty', ), 'prev' => array ( 0 => 'reflectionproperty.isdefault.php', 1 => 'ReflectionProperty::isDefault', ), 'next' => array ( 0 => 'reflectionproperty.isprivate.php', 1 => 'ReflectionProperty::isPrivate', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/reflection/reflectionproperty/isinitialized.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 7 >= 7.4.0, PHP 8)
ReflectionProperty::isInitialized — プロパティが初期化されているかをチェックする
object
プロパティが static でない場合、プロパティを取得する対象のオブジェクトを与えなければなりません。
プロパティがアクセス不能な場合、 ReflectionException がスローされます。 ReflectionProperty::setAccessible() を使えば、protected や private なプロパティをアクセス可能にすることが出来ます。
バージョン | 説明 |
---|---|
8.0.0 |
object は、nullable になりました。
|
例1 ReflectionProperty::isInitialized() の例
<?php
class User
{
public string $name;
}
$rp = new ReflectionProperty('User', 'name');
$user = new User;
var_dump($rp->isInitialized($user));
$user->name = 'Nikita';
var_dump($rp->isInitialized($user));
?>
上の例の出力は以下となります。
bool(false) bool(true)