Symfony\Component\Form\PropertyPath::setValue PHP Method

setValue() public method

Example: $path = new PropertyPath('child.name'); echo $path->setValue($object, '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.
public setValue ( object | array &$objectOrArray, $value ) : mixed
$objectOrArray object | array The object or array to traverse
return mixed The value at the end of the property path
    public function setValue(&$objectOrArray, $value)
    {
        $this->updatePropertyPath($objectOrArray, 0, $value);
    }

Usage Example

Example #1
0
 public function testSetValueThrowsExceptionIfGetterIsNotPublic()
 {
     $path = new PropertyPath('privateSetter');
     $this->setExpectedException('Symfony\\Component\\Form\\Exception\\PropertyAccessDeniedException');
     $path->setValue(new Author(), 'foobar');
 }