File tree 1 file changed +36
-0
lines changed
components/expression_language
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,42 @@ JavaScript::
94
94
95
95
This will print out ``Hi Hi Hi! ``.
96
96
97
+ Nullsafe operator
98
+ ~~~~~~~~~~~~~~~~~
99
+
100
+ Working with mutable objects can be, sometimes, error prone.
101
+ The ``?. `` syntax can help avoid unnecessary and redundant checks
102
+ when trying to access properties or methods on an object with dynamic structure::
103
+
104
+ class Apple
105
+ {
106
+ public $variety;
107
+ }
108
+
109
+ $apple = new Apple();
110
+ $apple->variety = 'Honeycrisp';
111
+
112
+ var_dump($expressionLanguage->evaluate(
113
+ 'fruit?.color',
114
+ [
115
+ 'fruit' => $apple,
116
+ ]
117
+ ));
118
+
119
+ This will print out ``null `` instead of throwing an ``Exception ``.
120
+
121
+ Similarly::
122
+
123
+ var_dump($expressionLanguage->evaluate(
124
+ 'fruit?.eatMe()',
125
+ [
126
+ 'fruit' => $apple,
127
+ ]
128
+ ));
129
+
130
+ Will print out ``null `` since the method ``eatMe() `` we trying to access
131
+ on the same ``Apple `` object does not exist.
132
+
97
133
.. _component-expression-functions :
98
134
99
135
Working with Functions
You can’t perform that action at this time.
0 commit comments