8000 [PropertyAccess] Fix nullsafe operator on array index by HypeMC · Pull Request #50280 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@HypeMC
Copy link
Member
@HypeMC HypeMC commented May 9, 2023
Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Currently the nullsafe operator doesn't work with array index paths. However, this is not obvious at first since THROW_ON_INVALID_PROPERTY_PATH is not enabled by default:

use Symfony\Component\PropertyAccess\PropertyAccessor;

var_dump((new PropertyAccessor())->getValue([], '[foo]')); // NULL
var_dump((new PropertyAccessor())->getValue([], '[foo?]')); // NULL

var_dump((new PropertyAccessor(throw: PropertyAccessor::THROW_ON_INVALID_INDEX))->getValue([], '[foo]'));
// Cannot read index "foo" while trying to traverse path "[foo]".

var_dump((new PropertyAccessor(throw: PropertyAccessor::THROW_ON_INVALID_INDEX))->getValue([], '[foo?]'));
// Cannot read index "foo" while trying to traverse path "[foo]". (THIS IS WRONG, SHOULD BE NULL)

@nicolas-grekas
Copy link
Member

Thank you @HypeMC.

@nicolas-grekas nicolas-grekas merged commit a689085 into symfony:6.2 May 19, 2023
@HypeMC HypeMC deleted the fix-nullsafe-index branch May 19, 2023 07:50
This was referenced May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0