Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: ReflectionProperty::isInitialized - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionProperty::isInitialized

2025-05-01

ReflectionProperty::isInitialized

(PHP 7 >= 7.4.0, PHP 8)

ReflectionProperty::isInitializedChecks whether a property is initialized

说明

public ReflectionProperty::isInitialized(?object $object = null): bool

Checks 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

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3