Merge branch '2.3' into 2.7

* 2.3:
  Fix PropertyAccessor modifying array in object when array key does not exist
This commit is contained in:
Fabien Potencier 2015-10-05 09:28:51 +02:00
commit 2c46204001
2 changed files with 12 additions and 1 deletions

View File

@ -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) {

View File

@ -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
*/