Skip to content

Commit

Permalink
bug #16090 Fix PropertyAccessor modifying array in object when array …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Oct 5, 2015
2 parents af2768c + f24c678 commit 58bf830
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Expand Up @@ -118,7 +118,9 @@ private function &readPropertiesUntil(&$objectOrArray, PropertyPathInterface $pr
(is_array($objectOrArray) && !array_key_exists($property, $objectOrArray))
)
) {
$objectOrArray[$property] = $i + 1 < $propertyPath->getLength() ? array() : null;
if ($i + 1 < $propertyPath->getLength()) {
$objectOrArray[$property] = array();
}
}

if ($isIndex) {
Expand Down
Expand Up @@ -103,6 +103,15 @@ public function testGetValueReadsProperty()
$this->assertEquals('Bernhard', $this->propertyAccessor->getValue($object, 'firstName'));
}

public function testGetValueNotModifyObject()
{
$object = new Author();
$object->firstName = array('Bernhard');

$this->assertNull($this->propertyAccessor->getValue($object, 'firstName[1]'));
$this->assertSame(array('Bernhard'), $object->firstName);
}

public function testGetValueIgnoresSingular()
{
$this->markTestSkipped('This feature is temporarily disabled as of 2.1');
Expand Down

0 comments on commit 58bf830

Please sign in to comment.