Skip to content

Commit db93585

Browse files
Merge branch '6.2' into 6.3
* 6.2: [Serializer] Fix SerializedPath not working with constructor arguments [FrameworkBundle] Fix Workflow without a marking store definition uses marking store definition of previously defined workflow [HttpFoundation] UrlHelper is now aware of RequestContext changes UrlHelper is now aware of RequestContext changes [Process] Stop the process correctly even if underlying input stream is not closed: Fix get sender name in turbosms notifier [Notifier] Update AmazonSns url in doc from de to en [PropertyInfo] Fix `PhpStanExtractor` when constructor has no docblock [PropertyAccess] Fix nullsafe operator on array index
2 parents b8a1a92 + 77442a9 commit db93585

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ private function readPropertiesUntil(array $zval, PropertyPathInterface $propert
304304
if (($zval[self::VALUE] instanceof \ArrayAccess && !$zval[self::VALUE]->offsetExists($property))
305305
|| (\is_array($zval[self::VALUE]) && !isset($zval[self::VALUE][$property]) && !\array_key_exists($property, $zval[self::VALUE]))
306306
) {
307-
if (!$ignoreInvalidIndices) {
307+
if (!$ignoreInvalidIndices && !$isNullSafe) {
308308
if (!\is_array($zval[self::VALUE])) {
309309
if (!$zval[self::VALUE] instanceof \Traversable) {
310310
throw new NoSuchIndexException(sprintf('Cannot read index "%s" while trying to traverse path "%s".', $property, (string) $propertyPath));

Tests/PropertyAccessorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,28 @@ public static function getValidReadPropertyPaths(): iterable
573573
yield [(object) ['foo' => null], 'foo?.bar.baz', null];
574574
yield [(object) ['foo' => (object) ['bar' => null]], 'foo?.bar?.baz', null];
575575
yield [(object) ['foo' => (object) ['bar' => null]], 'foo.bar?.baz', null];
576+
577+
yield from self::getNullSafeIndexPaths();
578+
}
579+
580+
public static function getNullSafeIndexPaths(): iterable
581+
{
576582
yield [(object) ['foo' => ['bar' => null]], 'foo[bar?].baz', null];
577583
yield [[], '[foo?]', null];
578584
yield [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?]', null];
579585
yield [['foo' => ['firstName' => 'Bernhard']], '[foo][bar?][baz?]', null];
580586
}
581587

588+
/**
589+
* @dataProvider getNullSafeIndexPaths
590+
*/
591+
public function testNullSafeIndexWithThrowOnInvalidIndex($objectOrArray, $path, $value)
592+
{
593+
$this->propertyAccessor = new PropertyAccessor(PropertyAccessor::DISALLOW_MAGIC_METHODS, PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH);
594+
595+
$this->assertSame($value, $this->propertyAccessor->getValue($objectOrArray, $path));
596+
}
597+
582598
public function testTicket5755()
583599
{
584600
$object = new Ticket5775Object();

0 commit comments

Comments
 (0)