8000 bug #42672 [PropertyAccess] Fix Regression in PropertyAccessor::isWri… · symfony/symfony@683c4f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 683c4f6

Browse files
committed
bug #42672 [PropertyAccess] Fix Regression in PropertyAccessor::isWritable() (haase-fabian)
This PR was squashed before being merged into the 5.3 branch. Discussion ---------- [PropertyAccess] Fix Regression in PropertyAccessor::isWritable() | Q | A | ------------- | --- | Branch? | 5.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT 1. is_object() check was moved to the isWritable() method. 2. adds test to check for false as return value of isWritable method Since commit [6f6c1a1](6f6c1a1) a regression exists where calling `$propertyAccessor->isWritable()` threw an `TypeError` when passing an array while using dot notation. `$propertyAccessor->isWritable(["name" => "Bernard"], "name");` > TypeError: Argument 1 passed to Symfony\Component\PropertyAccess\PropertyAccessor::isPropertyWritable() must be an object, array given Commits ------- 5cb8312 [PropertyAccess] Fix Regression in PropertyAccessor::isWritable()
2 parents 5a2952d + 5cb8312 commit 683c4f6

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,8 @@ public function isWritable($objectOrArray, $propertyPath)
313313
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
314314
return false;
315315
}
316-
} else {
317-
if (!$this->isPropertyWritable($zval[self::VALUE], $property 8000 Path->getElement($i))) {
318-
return false;
319-
}
316+
} elseif (!\is_object($zval[self::VALUE]) || !$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
317+
return false;
320318
}
321319

322320
if (\is_object($zval[self::VALUE])) {
@@ -663,10 +661,6 @@ private function getWriteInfo(string $class, string $property, $value): Property
663661
*/
664662
private function isPropertyWritable(object $object, string $property): bool
665663
{
666-
if (!\is_object($object)) {
667-
return false;
668-
}
669-
670664
$mutatorForArray = $this->getWriteInfo(\get_class($object), $property, []);
671665

672666
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType() || ($object instanceof \stdClass && property_exists($object, $property))) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public function getValidPropertyPaths()
3838
];
3939
}
4040

41+
public function getInvalidPropertyPaths()
42+
{
43+
return [
44+
[$this->getContainer(['firstName' => 'Bernhard']), 'firstName', 'Bernhard'],
45+
[$this->getContainer(['person' => $this->getContainer(['firstName' => 'Bernhard'])]), 'person.firstName', 'Bernhard'],
46+
];
47+
}
48+
4149
/**
4250
* @dataProvider getValidPropertyPaths
4351
*/
@@ -83,4 +91,12 @@ public function testIsWritable($collection, $path)
8391
{
8492
$this->assertTrue($this->propertyAccessor->isWritable($collection, $path));
8593
}
94+
95+
/**
96+
* @dataProvider getInvalidPropertyPaths
97+
*/
98+
public function testIsNotWritable($collection, $path)
99+
{
100+
$this->assertFalse($this->propertyAccessor->isWritable($collection, $path));
101+
}
86102
}

0 commit comments

Comments
 (0)
0