8000 bug #16090 Fix PropertyAccessor modifying array in object when array … · symfony/symfony@58bf830 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58bf830

Browse files
committed
bug #16090 Fix PropertyAccessor modifying array in object when array key does no… (pierredup)
This PR was merged into the 2.3 branch. Discussion ---------- Fix PropertyAccessor modifying array in object when array key does no… | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #16056 | License | MIT | Doc PR | Commits ------- f24c678 Fix PropertyAccessor modifying array in object when array key does not exist
2 parents af2768c + f24c678 commit 58bf830

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr
118118
(is_array($objectOrArray) && !array_key_exists($property, $objectOrArray))
119119
)
120120
) {
121-
$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
121+
if ($i + 1 < $propertyPath->getLength()) {
122+
$objectOrArray[$property] = array();
123+
}
122124
}
123125

124126
if ($isIndex) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ public function testGetValueReadsProperty()
103103
$this->assertEquals('Bernhard', $this->propertyAccessor->getValue($object, 'firstName'));
104104
}
105105

106+
public function testGetValueNotModifyObject()
107+
{
108+
$object = new Author();
109+
$object->firstName = array('Bernhard');
110+
111+
$this->assertNull($this->propertyAccessor->getValue($object, 'firstName[1]'));
112+
$this->assertSame(array('Bernhard'), $object->firstName);
113+
}
114+
106115
public function testGetValueIgnoresSingular()
107116
{
108117
$this->markTestSkipped('This feature is temporarily disabled as of 2.1');

0 commit comments

Comments
 (0)
0