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:
commit
2c46204001
@ -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) {
|
||||
|
@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user