@@ -99,6 +99,8 @@ JavaScript::
99
99
100
100
This will print out ``Hi Hi Hi! ``.
101
101
102
+ .. _component-expression-null-safe-operator :
103
+
102
104
Null-safe Operator
103
105
..................
104
106
@@ -118,6 +120,29 @@ operator)::
118
120
119
121
The null safe operator was introduced in Symfony 6.1.
120
122
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
+
121
146
.. _component-expression-functions :
122
147
123
148
Working with Functions
@@ -391,6 +416,12 @@ Ternary Operators
391
416
* ``foo ?: 'no' `` (equal to ``foo ? foo : 'no' ``)
392
417
* ``foo ? 'yes' `` (equal to ``foo ? 'yes' : '' ``)
393
418
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
+
394
425
Built-in Objects and Variables
395
426
------------------------------
396
427
@@ -401,3 +432,5 @@ expressions (e.g. the request, the current user, etc.):
401
432
* :doc: `Variables available in security expressions </security/expressions >`;
402
433
* :doc: `Variables available in service container expressions </service_container/expression_language >`;
403
434
* :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