diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index f063e8f007..aae083e4b7 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -82,11 +82,16 @@ class PropertyAccessor implements PropertyAccessorInterface */ public function getValue($objectOrArray, $propertyPath) { - $propertyPath = $this->getPropertyPath($propertyPath); - $zval = [ self::VALUE => $objectOrArray, ]; + + if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) { + return $this->readProperty($zval, $propertyPath)[self::VALUE]; + } + + $propertyPath = $this->getPropertyPath($propertyPath); + $propertyValues = $this->readPropertiesUntil($zval, $propertyPath, $propertyPath->getLength(), $this->ignoreInvalidIndices); return $propertyValues[\count($propertyValues) - 1][self::VALUE]; @@ -97,6 +102,22 @@ class PropertyAccessor implements PropertyAccessorInterface */ public function setValue(&$objectOrArray, $propertyPath, $value) { + if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) { + $zval = [ + self::VALUE => $objectOrArray, + ]; + + try { + $this->writeProperty($zval, $propertyPath, $value); + + return; + } catch (\TypeError $e) { + self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath); + // It wasn't thrown in this class so rethrow it + throw $e; + } + } + $propertyPath = $this->getPropertyPath($propertyPath); $zval = [