Support null coalescing operator (??) in templates


Well-known member
It would be really nice if the ?? operator (aka null coalescing operator) was supported in XF templates.

For example;
$ ?? 'default'
Which has the logic;
If $entity is null, or if property does not exist in $entity, or $entity->property is null, then the value of 'default' is returned.

This would essentially simplify this style of logic significantly;
($entity && $reaction.isValidKey('property') && $ !== null) ? $ : 'default'
Upvote 8
Agree. Null coalescing introduced in PHP 7.0, XenForo requires PHP 7.0 as minimal since XF 2.2, so it will be nice to see ability use them in templates :)
Top Bottom