8000 Fix PropertyAccessor modifying array in object when array key does no… by pierredup · Pull Request #16090 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix PropertyAccessor modifying array in object when array key does no… #16090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix PropertyAccessor modifying array in object when array key does no…
…t exist
  • Loading branch information
pierredup committed Oct 3, 2015
commit f24c678027ed33 8000 15ca02f2335105dc3257b981eb
4 changes: 3 additions & 1 deletion src/Symfony/Component/PropertyAccess/PropertyAccessor.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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