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:
commit
c1cb357d3a
|
@ -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]))
|
(is_array($zval[self::VALUE]) && !isset($zval[self::VALUE][$property]) && !array_key_exists($property, $zval[self::VALUE]))
|
||||||
) {
|
) {
|
||||||
if ($i + 1 < $propertyPath->getLength()) {
|
if ($i + 1 < $propertyPath->getLength()) {
|
||||||
$zval[self::VALUE][$property] = array();
|
|
||||||
|
|
||||||
if (isset($zval[self::REF])) {
|
if (isset($zval[self::REF])) {
|
||||||
|
$zval[self::VALUE][$property] = array();
|
||||||
$zval[self::REF] = $zval[self::VALUE];
|
$zval[self::REF] = $zval[self::VALUE];
|
||||||
|
} else {
|
||||||
|
$zval[self::VALUE] = array($property => array());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,11 @@ class PropertyAccessorTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
|
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()
|
public function testGetValueReadsProperty()
|
||||||
|
|
Reference in New Issue