ReflectionProperty::isInitialized

(PHP 7 >= 7.4.0, PHP 8)

ReflectionProperty::isInitializedChecks whether a property is initialized

Descripción

publicReflectionProperty::isInitialized(?object$object = null): bool

Checks whether a property is initialized.

Parámetros

object

If the property is non-static an object must be provided to fetch the property from.

Valores devueltos

Returns false for typed properties prior to initialization, and for properties that have been explicitly unset(). For all other properties true will be returned.

Errores/Excepciones

Throws a ReflectionException if the property is inaccessible. You can make a protected or private property accessible using ReflectionProperty::setAccessible().

Historial de cambios

VersiónDescripción
8.0.0object is nullable now.

Ejemplos

Ejemplo #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));
?>

El resultado del ejemplo sería:

bool(false) bool(true)

Ver también

To Top