Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PropertyAccess] Fix nullsafe operator on array index #50280

Merged
merged 1 commit into from May 19, 2023

Conversation

HypeMC
Copy link
Contributor

@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
9 checks passed
@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.

None yet

3 participants