bug #18603 [PropertyAccess] ->getValue() should be read-only (nicolas-grekas)

This PR was merged into the 2.3 branch.

Discussion
----------

[PropertyAccess] ->getValue() should be read-only

| Q             | A
| ------------- | ---
| Branch?       | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18601
| License       | MIT
| Doc PR        | -

Commits
-------

fa68529 [PropertyAccess] ->getValue() should be read-only
This commit is contained in:
Nicolas Grekas 2016-04-20 20:37:31 +02:00
commit c1cb357d3a
2 changed files with 7 additions and 4 deletions

View File

@ -275,10 +275,11 @@ class PropertyAccessor implements PropertyAccessorInterface
(is_array($zval[self::VALUE]) && !isset($zval[self::VALUE][$property]) && !array_key_exists($property, $zval[self::VALUE]))
) {
if ($i + 1 < $propertyPath->getLength()) {
$zval[self::VALUE][$property] = array();
if (isset($zval[self::REF])) {
$zval[self::VALUE][$property] = array();
$zval[self::REF] = $zval[self::VALUE];
} else {
$zval[self::VALUE] = array($property => array());
}
}
}

View File

@ -92,9 +92,11 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
{
$array = array('child' => array('index' => array()));
$object = new \ArrayObject();
$array = array('child' => array('index' => $object));
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][firstName]'));
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][foo][bar]'));
$this->assertSame(array(), $object->getArrayCopy());
}
public function testGetValueReadsProperty()