Skip to content

Commit 92db003

Browse files
Vincznicolas-grekas
authored andcommitted
[PropertyAccess] Fix nullsafe chain like x?.y
1 parent 813491f commit 92db003

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ private function readPropertiesUntil(array $zval, PropertyPathInterface $propert
345345
}
346346

347347
$propertyValues[] = $zval;
348+
349+
if ($isNullSafe && null === $zval[self::VALUE]) {
350+
break;
351+
}
348352
}
349353

350354
return $propertyValues;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ public function getValidReadPropertyPaths(): iterable
569569
yield [(object) [], 'foo?', null];
570570
yield [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?', null];
571571
yield [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?.baz?', null];
572+
yield [(object) ['foo' => null], 'foo?.bar', null];
573+
yield [(object) ['foo' => null], 'foo?.bar.baz', null];
574+
yield [(object) ['foo' => (object) ['bar' => null]], 'foo?.bar?.baz', null];
575+
yield [(object) ['foo' => (object) ['bar' => null]], 'foo.bar?.baz', null];
576+
yield [(object) ['foo' => ['bar' => null]], 'foo[bar?].baz', null];
572577
yield [[], '[foo?]', null];
573578
yield [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?]', null];
574579
yield [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?][baz?]', null];

0 commit comments

Comments
 (0)