Symfony\Component\PropertyAccess\PropertyAccessorInterface::setValue
Sets the value at the end of the property path of the object
Example: use Symfony\Component\PropertyAccess\PropertyAccess; $propertyAccessor = PropertyAccess::getPropertyAccessor(); echo $propertyAccessor->setValue($object, 'child.name', 'Fabien'); // equals echo $object->getChild()->setName('Fabien'); This method first tries to find a public setter for each property in the path. The name of the setter must be the camel-cased property name prefixed with "set". If the setter does not exist, this method tries to find a public property. The value of the property is then changed. If neither is found, an exception is thrown.
Signature
public function setValue(object|array&
$objectOrArray,
string|PropertyPathInterface
$propertyPath,
mixed
$value )
Parameters
$objectOrArray
— object- The object or array to modify
$propertyPath
— object- The property path to modify
$value
— mixed- The value to set at the end of the property path
Errors/Exceptions
-
NoSuchPropertyException
- If a property does not exist or is not public.
-
UnexpectedTypeException
- If a value within the path is neither object