Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@mytuny
Copy link
Contributor

QA
Branch?6.1
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#45411,#21691
LicenseMIT
Doc PRsymfony/symfony-docs#16743

This is another waited feature for the syntax of the expression-language component. Thenull-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 withisset() (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.

@carsonbotcarsonbot added this to the6.1 milestoneApr 22, 2022
@carsonbotcarsonbot changed the title[ExpressionLanguage] [Feature] Add support for null coalescing syntax[ExpressionLanguage] Add support for null coalescing syntaxApr 22, 2022
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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!

@fabpotfabpot modified the milestones:6.1,6.2May 8, 2022
Copy link
Member

@nicolas-grekasnicolas-grekas left a comment
edited
Loading

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)

@nicolas-grekas
Copy link
Member

Can you please rebase? This conflicts after#46454
Please also double check that the issue fixed in#46454 didn't happen here just in case.

@kvailas
Copy link

Hello@nicolas-grekas , many many many thanks for working on this one!
Is there a plan to release the new feature within the month or so?
It would be great to know!

@fabpot
Copy link
Member

@kvailas Seehttps://symfony.com/doc/current/contributing/community/releases.html for more information about our release process.
If this PR is merged in the next couple of months, it will be part of 6.2.

kvailas reacted with thumbs up emoji

@kvailas
Copy link

kvailas commentedJul 20, 2022
edited
Loading

@fabpot actually i am using the expression language library as part of anon-symfony based project. Just loading the library in order to use the expression language from its respective repo.

Thanks for your input, appreciated.

@stof
Copy link
Member

@kvailas this does not changewhen the releases of the components happen (btw, Symfony-based projects also download components from the subtree-split repos)

@fabpot
Copy link
Member

Can you rebase on current 6.2?

@fabpot
Copy link
Member

Thank you@mytuny.

@fabpotfabpotforce-pushed thefeature/expression-language/null-coalescing branch fromfaf40df to8e3c505CompareJuly 25, 2022 12:31
@fabpotfabpot merged commit39191b4 intosymfony:6.2Jul 25, 2022
@fabpot
Copy link
Member

FYI, follow-up PR here:#47058

@fabpotfabpot mentioned this pull requestOct 24, 2022
}
};

yield ['foo.bar ?? "default"',null];

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

jseparovic1 reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+1 more reviewer

@syntaxerrosyntaxerrosyntaxerro left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

6.2

Development

Successfully merging this pull request may close these issues.

Expression Language package: doesn't handle the absence of the property and an error displays

7 participants

@mytuny@nicolas-grekas@kvailas@fabpot@stof@syntaxerro@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp