diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index f6c0c636d43be..76ef8c1d5cfb6 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -118,7 +118,9 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr (is_array($objectOrArray) && !array_key_exists($property, $objectOrArray)) ) ) { - $objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null; + if ($i + 1 < $propertyPath->getLength()) { + $objectOrArray[$property] = array(); + } } if ($isIndex) { diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index fec4e14b0940b..87287048a7752 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -103,6 +103,15 @@ public function testGetValueReadsProperty() $this->assertEquals('Bernhard', $this->propertyAccessor->getValue($object, 'firstName')); } + public function testGetValueNotModifyObject() + { + $object = new Author(); + $object->firstName = array('Bernhard'); + + $this->assertNull($this->propertyAccessor->getValue($object, 'firstName[1]')); + $this->assertSame(array('Bernhard'), $object->firstName); + } + public function testGetValueIgnoresSingular() { $this->markTestSkipped('This feature is temporarily disabled as of 2.1');