Skip to content

Commit 81204c3

Browse files
committed
[ExpressionLanguage] Feature Null-coalescing operator
1 parent b94166f commit 81204c3

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)