Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[ExpressionLanguage] Feature Null-coalescing operator#16743
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
javiereguiluz merged 1 commit intosymfony:6.1frommytuny:feature/expression-language/null-coalescingJul 29, 2022
Merged
[ExpressionLanguage] Feature Null-coalescing operator#16743
javiereguiluz merged 1 commit intosymfony:6.1frommytuny:feature/expression-language/null-coalescingJul 29, 2022
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
fabpot added a commit to symfony/symfony that referenced this pull requestJul 25, 2022
…yntax (mytuny)This PR was merged into the 6.2 branch.Discussion----------[ExpressionLanguage] Add support for null coalescing syntax| Q | A| ------------- | ---| Branch? | 6.1| Bug fix? | no| New feature? | yes| Deprecations? | no| Tickets |Fix#45411,#21691| License | MIT| Doc PR |symfony/symfony-docs#16743This is another waited feature for the syntax of the expression-language component. The [null-coalescing](https://wiki.php.net/rfc/isset_ternary) 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's ``null``. Note that this coalescing behavior can be chained and the validation logic takes decreasing priority from left to right.Commits-------8e3c505 [ExpressionLanguage] Add support for null coalescing syntax
Member
javiereguiluz commentedJul 29, 2022
Sofien, thanks a lot for contributing this nice feature and its docs ... and congrats on your first Symfony Docs contribution 🎉 |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[ExpressionLanguage] [NEW FEATURE]
This PR introduces the support for null-coalescing operator
??.The proposed change, includes a paragraph under the sub-page /expression_language/syntax to describe the new feature usage. The sub-paragraph has a title ofNull-coalescing operator under the paragraphSupported Operators.
The actual work related to this Doc PR available as Symfony PR .