ReflectionProperty::isInitialized()
(PHP 7 >= 7.4.0)
Checks whether a property is initialized
说明
public ReflectionProperty::isInitialized([object $object] ): bool
Checks whether a property is initialized.
参数
- $object
If the property is non-static an object must be provided to fetch the property from.
返回值
ReturnsFALSE
for typed properties prior to initialization, and for properties that have been explicitlyunset(). For all other propertiesTRUE
will be returned.
错误/异常
Throws aReflectionExceptionif the property is inaccessible. You can make a protected or private property accessible usingReflectionProperty::setAccessible().
范例
Example #1ReflectionProperty::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)
参见
- ReflectionProperty::hasType() Checks if property has a type