Skip to content

Commit bd72b38

Browse files
committed
Readd the docs about Null Coalescing Operator
1 parent 3a68a52 commit bd72b38

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/expression_language/syntax.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,23 @@ 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 `null-coalescing operator`_, which combines
350+
the ternary operator and ``isset()``. It returns the left hand-side if it exists
351+
and it's not ``null``; otherwise it returns the right hand-side. Note that you
352+
can chain multiple coalescing operators.
353+
354+
* ``foo ?? 'no'``
355+
* ``foo.baz ?? 'no'``
356+
* ``foo[3] ?? 'no'``
357+
* ``foo.baz ?? foo['baz'] ?? 'no'``
358+
359+
.. versionadded:: 6.2
360+
361+
The null-coalescing operator was introduced in Symfony 6.2.
362+
346363
Built-in Objects and Variables
347364
------------------------------
348365

0 commit comments

Comments
 (0)