php8.5
Home/ Manual/ reflection / reflectionproperty/ ReflectionProperty::isDefault

ReflectionProperty::isDefault

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Checks if property is a default property

Description

ReflectionProperty::isDefault(): bool

Checks whether the property was declared at compile-time, or whether the property was dynamically declared at run-time.

Parameters Parameters

Return Values

true if the property was declared at compile-time, or false if it was created at run-time.

Examples

ReflectionProperty::isDefault example

php
<?php

#[\AllowDynamicProperties]
class Foo {
    public $bar;
}

$o = new Foo();
$o->bar = 42;
$o->baz = 42;

$ro = new ReflectionObject($o);
var_dump($ro->getProperty('bar')->isDefault());
var_dump($ro->getProperty('baz')->isDefault());
?>

The above example will output:

output
bool(true)
bool(false)

See Also

  • ReflectionProperty::getValue

Source: reference/reflection/reflectionproperty/isdefault.xml · from the official PHP manual (php/doc-en)