PHP - Manual: ReflectionProperty::isInitialized
2024-11-23
(PHP 7 >= 7.4.0, PHP 8)
ReflectionProperty::isInitialized — Checks whether a property is initialized
$object
= null
): boolChecks whether a property is initialized.
object
If the property is non-static an object must be provided to fetch the property from.
Returns false
for typed properties prior to initialization,
and for properties that have been explicitly unset().
For all other properties true
will be returned.
Throws a ReflectionException if the property is inaccessible. You can make a protected or private property accessible using ReflectionProperty::setAccessible().
版本 | 说明 |
---|---|
8.0.0 |
object is nullable now.
|
示例 #1 ReflectionProperty::isInitialized() example
<?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)
官方地址:https://www.php.net/manual/en/reflectionproperty.isinitialized.php