PHP 8.0.0 Beta 4 available for testing

ReflectionProperty::isInitialized

(PHP 7 >= 7.4.0)

ReflectionProperty::isInitializedChecks whether a property is initialized

Descrição

public ReflectionProperty::isInitialized ([ object $object ] ) : 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.

Valor Retornado

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

Erros

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

Exemplos

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

O exemplo acima irá imprimir:

bool(false)
bool(true)

Veja Também

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top