If the class doesn't have a property with the given name, a ReflectionException will be raised.
(PHP 5, PHP 7, PHP 8)
ReflectionClass::getProperty — Obtiene un objeto ReflectionProperty para una propiedad de una clase
Obtiene un objeto ReflectionProperty para una propiedad de una clase.
name
El nombre de la propiedad.
Un objeto ReflectionProperty.
Ejemplo #1 Uso básico de ReflectionClass::getProperty()
<?php
$clase = new ReflectionClass('ReflectionClass');
$propiedad = $clase->getProperty('name');
var_dump($propiedad);
?>
El resultado del ejemplo sería:
object(ReflectionProperty)#2 (2) { ["name"]=> string(4) "name" ["class"]=> string(15) "ReflectionClass" }
If the class doesn't have a property with the given name, a ReflectionException will be raised.
Accessing private properties is possible, but care must be taken if that private property was defined lower into the inheritance chain. For example, if class A extends class B, and class B defines a private property called 'foo', getProperty will throw a ReflectionException.
Instead, you can loop over getParentClass until it returns false to look for the private property, at which point you can access and/or modify its value as needed.