ReflectionProperty::setValue
Définit la valeur de la propriété
&reftitle.description;
public voidReflectionProperty::setValue
objectobject
mixedvalue
public voidReflectionProperty::setValue
mixedvalue
Définit (modifie) la valeur de la propriété.
&reftitle.parameters;
object
L'objet à utiliser dans le cas d'une propriété non statique.
Si la propriété est statique, nul besoin de préciser un objet, seul
value est nécessaire.
value
La nouvelle valeur.
&reftitle.returnvalues;
&return.void;
&reftitle.errors;
Émet une ReflectionException si la propriété est inaccessible.
Vous pouvez transformer une propriété protégée ou privée en publique grâce à
ReflectionProperty::setAccessible.
&reftitle.examples;
Exemple avec ReflectionProperty::setValue
getProperty('staticProperty')->setValue('foo');
var_dump(Foo::$staticProperty);
$foo = new Foo;
$reflectionClass->getProperty('property')->setValue($foo, 'bar');
var_dump($foo->property);
$reflectionProperty = $reflectionClass->getProperty('privateProperty');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($foo, 'foobar');
var_dump($reflectionProperty->getValue($foo));
?>
]]>
&example.outputs;
&reftitle.seealso;
ReflectionProperty::getValue
ReflectionProperty::setAccessible
ReflectionClass::setStaticPropertyValue