@@ -94,6 +94,8 @@ JavaScript::
9494
9595This will print out ``Hi Hi Hi! ``.
9696
97+ .. _component-expression-null-safe-operator :
98+
9799Null-safe Operator
98100..................
99101
@@ -109,6 +111,25 @@ operator)::
109111 $expressionLanguage->evaluate('fruit?.color', ['fruit' => '...'])
110112 $expressionLanguage->evaluate('fruit?.getStock()', ['fruit' => '...'])
111113
114+ .. _component-expression-null-coalescing-operator :
115+
116+ Null-Coalescing Operator
117+ ........................
118+
119+ It returns the left-hand side if it exists and it's not ``null ``; otherwise it
120+ returns the right-hand side. Expressions can chain multiple coalescing operators:
121+
122+ * ``foo ?? 'no' ``
123+ * ``foo.baz ?? 'no' ``
124+ * ``foo[3] ?? 'no' ``
125+ * ``foo.baz ?? foo['baz'] ?? 'no' ``
126+
127+ .. note ::
128+
129+ The main difference with the `null-coalescing operator in PHP `_ is that
130+ ExpressionLanguage will throw an exception when trying to access a
131+ non-existent variable.
132+
112133.. _component-expression-functions :
113134
114135Working with Functions
@@ -370,6 +391,12 @@ Ternary Operators
370391* ``foo ?: 'no' `` (equal to ``foo ? foo : 'no' ``)
371392* ``foo ? 'yes' `` (equal to ``foo ? 'yes' : '' ``)
372393
394+ Other Operators
395+ ~~~~~~~~~~~~~~~
396+
397+ * ``?. `` (:ref: `null-safe operator <component-expression-null-safe-operator >`)
398+ * ``?? `` (:ref: `null-coalescing operator <component-expression-null-coalescing-operator >`)
399+
373400Built-in Objects and Variables
374401------------------------------
375402
@@ -380,3 +407,5 @@ expressions (e.g. the request, the current user, etc.):
380407* :doc: `Variables available in security expressions </security/expressions >`;
381408* :doc: `Variables available in service container expressions </service_container/expression_language >`;
382409* :ref: `Variables available in routing expressions <routing-matching-expressions >`.
410+
411+ .. _`null-coalescing operator in PHP` : https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
0 commit comments