Reputation: 6136
Since PHP7, the null coalescent operator ($a ?? $b
) means isset($a) ? $a : $b
.
In my code, I often have facultative variables passed from the controller to the view and I need to set default values in the view if that variable isn't passed.
I would like something like this: $someVar ??= 42
(not working) that would mean $someVar = $someVar ?? 42
.
Is there such a shortcut to do that or do I have to stick to the long version? (Yeah, I know, it's not that long, but lazy people will be lazy).
Upvotes: 5
Views: 3577
Reputation: 29870
No. No such shortcut.
All PHP operators are linked from this page: Operators. And the details of null coalescing are on this one (not in the initial list, for some reason): Comparison Operators>Null Coalescing Operator.
Upvotes: 1