ReflectionProperty::__constructConstruit un nouvel objet ReflectionProperty
&reftitle.description;
publicReflectionProperty::__constructobjectstringclassstringproperty
&reftitle.parameters;
class
Soit une chaîne de caractères contenant le nom de la classe à introspecter,
ou un objet.
property
Le nom de la propriété à refléter.
&reftitle.errors;
Le fait de tenter de récupérer ou définir la valeur d'une propriété
privée ou protégée d'une classe émettra une exception.
&reftitle.examples;
Exemple avec ReflectionProperty::__construct
The%s%s%s%s property '%s' (which was %s)\n" .
" having the modifiers %s\n",
$prop->isPublic() ? ' public' : '',
$prop->isPrivate() ? ' private' : '',
$prop->isProtected() ? ' protected' : '',
$prop->isStatic() ? ' static' : '',
$prop->getName(),
$prop->isDefault() ? 'declared at compile-time' : 'created at run-time',
var_export(Reflection::getModifierNames($prop->getModifiers()), true)
);
// Création d'une instance de Str
$obj= new Str();
// Récupère la valeur courante
printf("---> Value is: ");
var_dump($prop->getValue($obj));
// Modifie la valeur
$prop->setValue($obj, 10);
printf("---> Setting value to 10, new value is: ");
var_dump($prop->getValue($obj));
// Affiche l'objet
var_dump($obj);
?>
]]>
&example.outputs.similar;
The public property 'length' (which was declared at compile-time)
having the modifiers array (
0 => 'public',
)
---> Value is: int(5)
---> Setting value to 10, new value is: int(10)
object(Str)#2 (1) {
["length"]=>
int(10)
}
]]>
Récupération d'une valeur depuis une propriété privée ou protégée en utilisant la classe ReflectionProperty
setAccessible(true);
var_dump($prop->getValue($obj)); // int(2)
$prop = new ReflectionProperty('Foo', 'z');
$prop->setAccessible(true);
var_dump($prop->getValue($obj)); // int(2)
?>
]]>
&example.outputs.similar;
&reftitle.seealso;
ReflectionProperty::getNameLes constructeurs