8000 bug #18603 [PropertyAccess] ->getValue() should be read-only (nicolas… · symfony/symfony@c1cb357 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1cb357

Browse files
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
2 parents 40b4cb2 + fa68529 commit c1cb357

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)
0