File tree 2 files changed +35
-12
lines changed
2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -80,19 +80,10 @@ The main class of the component is
80
80
Null Coalescing Operator
81
81
........................
82
82
83
- This is the same as the PHP `null-coalescing operator `_, which combines
84
- the ternary operator and ``isset() ``. It returns the left hand-side if it exists
85
- and it's not ``null ``; otherwise it returns the right hand-side. Note that you
86
- can chain multiple coalescing operators.
87
-
88
- * ``foo ?? 'no' ``
89
- * ``foo.baz ?? 'no' ``
90
- * ``foo[3] ?? 'no' ``
91
- * ``foo.baz ?? foo['baz'] ?? 'no' ``
92
-
93
- .. versionadded :: 6.2
83
+ .. note ::
94
84
95
- The null-coalescing operator was introduced in Symfony 6.2.
85
+ This content has been moved to the ref:`null coalescing operator <component-expression-null-coalescing-operator> `
86
+ section of ExpressionLanguage syntax reference page.
96
87
97
88
Parsing and Linting Expressions
98
89
...............................
@@ -405,3 +396,4 @@ or by using the second argument of the constructor::
405
396
406
397
.. _`AST` : https://en.wikipedia.org/wiki/Abstract_syntax_tree
407
398
.. _`CacheItemPoolInterface` : https://github.com/php-fig/cache/blob/master/src/CacheItemPoolInterface.php
399
+ .. _`null-coalescing operator in PHP` : https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce
Original file line number Diff line number Diff line change @@ -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
You can’t perform that action at this time.
0 commit comments