10000 Merge branch '2.3' into 2.7 · symfony/symfony@2c46204 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 2c46204

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: Fix PropertyAccessor modifying array in object when array key does not exist
2 parents d1f50c5 + 58bf830 commit 2c46204

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
@@ -239,7 +239,9 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr
239239
));
240240
}
241241

242-
$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
242+
if ($i + 1 < $propertyPath->getLength()) {
243+
$objectOrArray[$property] = array();
244+
}
243245
}
244246

245247
if ($isIndex) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ public function testGetValueReadsMagicGetThatReturnsConstant()
130130
$this->assertSame('constant value', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'constantMagicProperty'));
131131
}
132132

133+
public function testGetValueNotModifyObject()
134+
{
135+
$object = new \stdClass();
136+
$object->firstName = array('Bernhard');
137+
138+
$this->assertNull($this->propertyAccessor->getValue($object, 'firstName[1]'));
139+
$this->assertSame(array('Bernhard'), $object->firstName);
140+
}
141+
133142
/**
134143
* @expectedException \Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException
135144
*/

0 commit comments

Comments
 (0)
0