Skip to content

[ExpressionLanguage] Fix null-safe chaining #46454

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

Merged
merged 1 commit into from
May 27, 2022

Conversation

HypeMC
Copy link
Contributor

@HypeMC HypeMC commented May 25, 2022

Q A
Branch? 6.1
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Currently the null-safe operator in the expression language doesn't behave the same as in PHP. According to the RFC:

When the evaluation of one element in the chain fails the execution of the entire chain is aborted and the entire chain evaluates to null.

For example, in PHP the following expressions will return null:

$foo = null;
$foo?->bar['baz'];
$foo?->bar['baz']['qux'];
$foo?->bar['baz']['qux']->quux;
$foo?->bar['baz']['qux']->quux();

This, however, is not the case with the null-safe operator in the expression language where the evaluation for such cases fails.

Not sure if this qualifies as a bug fix or a feature, so please let me know.

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely a bugfix to me

@HypeMC HypeMC force-pushed the expression-nullsafe-chaining branch from b958c52 to e8479f9 Compare May 25, 2022 08:17
@HypeMC
Copy link
Contributor Author

HypeMC commented May 25, 2022

Made one minor change, I think it makes te code more readable ee94071

@fabpot
Copy link
Member

fabpot commented May 27, 2022

Thank you @HypeMC.

@fabpot fabpot force-pushed the expression-nullsafe-chaining branch from d2f24e0 to a39c25c Compare May 27, 2022 06:38
@fabpot fabpot merged commit 1b0cb41 into symfony:6.1 May 27, 2022
@HypeMC HypeMC deleted the expression-nullsafe-chaining branch May 27, 2022 07:07
@fabpot fabpot mentioned this pull request May 27, 2022
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.

5 participants