@@ -99,6 +99,8 @@ JavaScript::
9999
100100This will print out ``Hi Hi Hi! ``.
101101
102+ .. _component-expression-null-safe-operator :
103+
102104Null-safe Operator
103105..................
104106
@@ -118,6 +120,29 @@ operator)::
118120
119121 The null safe operator was introduced in Symfony 6.1.
120122
123+ .. _component-expression-null-coalescing-operator :
124+
125+ Null-Coalescing Operator
126+ ........................
127+
128+ It returns the left-hand side if it exists and it's not ``null ``; otherwise it
129+ returns the right-hand side. Expressions can chain multiple coalescing operators:
130+
131+ * ``foo ?? 'no' ``
132+ * ``foo.baz ?? 'no' ``
133+ * ``foo[3] ?? 'no' ``
134+ * ``foo.baz ?? foo['baz'] ?? 'no' ``
135+
136+ .. note ::
137+
138+ The main difference with the `null-coalescing operator in PHP `_ is that
139+ ExpressionLanguage will throw an exception when trying to access a
140+ non-existent variable.
141+
142+ .. versionadded :: 6.2
143+
144+ The null-coalescing operator was introduced in Symfony 6.2.
145+
121146.. _component-expression-functions :
122147
123148Working with Functions
@@ -391,6 +416,12 @@ Ternary Operators
391416* ``foo ?: 'no' `` (equal to ``foo ? foo : 'no' ``)
392417* ``foo ? 'yes' `` (equal to ``foo ? 'yes' : '' ``)
393418
419+ Other Operators
420+ ~~~~~~~~~~~~~~~
421+
422+ * ``?. `` (:ref: `null-safe operator <component-expression-null-safe-operator >`)
423+ * ``?? `` (:ref: `null-coalescing operator <component-expression-null-coalescing-operator >`)
424+
394425Built-in Objects and Variables
395426------------------------------
396427
@@ -401,3 +432,5 @@ expressions (e.g. the request, the current user, etc.):
401432* :doc: `Variables available in security expressions </security/expressions >`;
402433* :doc: `Variables available in service container expressions </service_container/expression_language >`;
403434* :ref: `Variables available in routing expressions <routing-matching-expressions >`.
435+
436+ .. _`null-coalescing operator in PHP` : https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
0 commit comments