Skip to content

Commit fa68529

Browse files
[PropertyAccess] ->getValue() should be read-only
1 parent 40b4cb2 commit fa68529

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,11 @@ private function readPropertiesUntil($zval, PropertyPathInterface $propertyPath,
275275
(is_array($zval[self::VALUE]) && !isset($zval[self::VALUE][$property]) && !array_key_exists($property, $zval[self::VALUE]))
276276
) {
277277
if ($i + 1 < $propertyPath->getLength()) {
278-
$zval[self::VALUE][$property] = array();
279-
280278
if (isset($zval[self::REF])) {
279+
$zval[self::VALUE][$property] = array();
281280
$zval[self::REF] = $zval[self::VALUE];
281+
} else {
282+
$zval[self::VALUE] = array($property => array());
282283
}
283284
}
284285
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ public function testGetValueReadsArrayWithCustomPropertyPath()
9292

9393
public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
9494
{
95-
$array = array('child' => array('index' => array()));
95+
$object = new \ArrayObject();
96+
$array = array('child' => array('index' => $object));
9697

97-
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][firstName]'));
98+
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][foo][bar]'));
99+
$this->assertSame(array(), $object->getArrayCopy());
98100
}
99101

100102
public function testGetValueReadsProperty()

0 commit comments

Comments
 (0)