Skip to content

Commit e5cec2c

Browse files
committed
[PropertyAccess] Fix using the nullsafe operator on first level properties
1 parent a11057f commit e5cec2c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function getValue(object|array $objectOrArray, string|PropertyPathInterfa
108108
self::VALUE => $objectOrArray,
109109
];
110110

111-
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[')) {
111+
if (\is_object($objectOrArray) && false === strpbrk((string) $propertyPath, '.[?')) {
112112
return $this->readProperty($zval, $propertyPath, $this->ignoreInvalidProperty)[self::VALUE];
113113
}
114114

Tests/PropertyAccessorTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,17 +561,17 @@ public function getValidWritePropertyPaths()
561561
];
562562
}
563563

564-
public function getValidReadPropertyPaths()
564+
public function getValidReadPropertyPaths(): iterable
565565
{
566-
$testCases = $this->getValidWritePropertyPaths();
566+
yield from $this->getValidWritePropertyPaths();
567567

568568
// Optional paths can only be read and can't be written to.
569-
$testCases[] = [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?', null];
570-
$testCases[] = [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?.baz?', null];
571-
$testCases[] = [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?]', null];
572-
$testCases[] = [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?][baz?]', null];
573-
574-
return $testCases;
569+
yield [(object) [], 'foo?', null];
570+
yield [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?', null];
571+
yield [(object) ['foo' => (object) ['firstName' => 'Bernhard']], 'foo.bar?.baz?', null];
572+
yield [[], '[foo?]', null];
573+
yield [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?]', null];
574+
yield [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?][baz?]', null];
575575
}
576576

577577
public function testTicket5755()

0 commit comments

Comments
 (0)