8000 minor #16743 [ExpressionLanguage] Feature Null-coalescing operator (m… · symfony/symfony-docs@3cc1163 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cc1163

Browse files
committed
minor #16743 [ExpressionLanguage] Feature Null-coalescing operator (mytuny)
This PR was merged into the 6.1 branch. Discussion ---------- [ExpressionLanguage] Feature Null-coalescing operator <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> [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 of **Null-coalescing operator** under the paragraph **Supported Operators**. The actual work related to this Doc PR available as Symfony PR <!--symfony/symfony#45795>. Commits ------- 81204c3 [ExpressionLanguage] Feature Null-coalescing operator
2 parents d8b7d70 + 81204c3 commit 3cc1163

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

components/expression_language/syntax.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,18 @@ Ternary Operators
343343
* ``foo ?: 'no'`` (equal to ``foo ? foo : 'no'``)
344344
* ``foo ? 'yes'`` (equal to ``foo ? 'yes' : ''``)
345345

346+
Null-coalescing Operator
347+
~~~~~~~~~~~~~~~~~~~~~~~~
348+
349+
This is the same as the PHP's null-coalescing operator ``??`` which is a syntactic sugar for the use of a ternary
350+
in conjunction with isset(). It returns the left hand-side if it exist and not ``null`` otherwise it returns the right hand-side.
351+
Note that coalescing can be chained.
352+
353+
* ``foo ?? 'no'``
354+
* ``foo.baz ?? 'no'``
355+
* ``foo[3] ?? 'no'``
356+
* ``foo.baz ?? foo['baz'] ?? 'no'``
357+
346358
Built-in Objects and Variables
347359
------------------------------
348360

0 commit comments

Comments
 (0)
0