diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php index b7b961c8d1..81d0eed0f7 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessor.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessor.php @@ -239,7 +239,9 @@ class PropertyAccessor implements PropertyAccessorInterface )); } - $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 51b712cf75..fb4e3c34ee 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -130,6 +130,15 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase $this->assertSame('constant value', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'constantMagicProperty')); } + public function testGetValueNotModifyObject() + { + $object = new \stdClass(); + $object->firstName = array('Bernhard'); + + $this->assertNull($this->propertyAccessor->getValue($object, 'firstName[1]')); + $this->assertSame(array('Bernhard'), $object->firstName); + } + /** * @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException */