-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ExpressionLanguage] Add support for null coalescing syntax #46142
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
[ExpressionLanguage] Add support for null coalescing syntax #46142
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
src/Symfony/Component/ExpressionLanguage/Node/CoalescingNode.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/ExpressionLanguage/Node/CoalescingNode.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/ExpressionLanguage/Node/CoalescingNode.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/ExpressionLanguage/Node/CoalescingNode.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/ExpressionLanguage/Node/NullCoalesceNode.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(please apply fabbot's path)
825d77f
to
faf40df
Compare
Hello @nicolas-grekas , many many many thanks for working on this one! |
@kvailas See https://symfony.com/doc/current/contributing/community/releases.html for more information about our release process. |
@fabpot actually i am using the expression language library as part of a non-symfony based project. Just loading the library in order to use the expression language from its respective repo. Thanks for your input, appreciated. |
@kvailas this does not change when the releases of the components happen (btw, Symfony-based projects also download components from the subtree-split repos) |
Can you rebase on current 6.2? |
Thank you @mytuny. |
faf40df
to
8e3c505
Compare
FYI, follow-up PR here: #47058 |
} | ||
}; | ||
|
||
yield ['foo.bar ?? "default"', null]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yield foo ?? 'default' <- will be red
This is another waited feature for the syntax of the expression-language component. The null-coalescing operator
??
becomes a need for variant programming needs these days.Following my previous PR introducing the null-safe operator (#45795). I'm hereby introducing yet another essential operator to make the syntax even more complete.
The null-coalescing operator is a syntactic sugar for a common use of ternary in conjunction with
isset()
(in PHP) or equivalent in other languages. This is such a common use-case to the point that almost all majors programming syntax nowadays support a sort of a short-hand for that operation namely coalescing operator. Now it's time for the syntax of Expression-Language to do so!Expressions like:
foo.bar ?? 'default'
foo[3] ?? 'default'
foo.bar ?? foo['bar'] ?? 'default'
will default to the expression in the right-hand-side of the
??
operator whenever the expression in the left-hand-side of it does not exist or it'snull
. Note that this coalescing behavior can be chained and the validation logic takes decreasing priority from left to right.