Support null coalescing operator (??) in templates

Xon

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

For example;
PHP:
$entity.property ?? '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;
PHP:
($entity && $reaction.isValidKey('property') && $reaction.property !== null) ? $reaction.property : 'default'
 
Upvote 19
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 :)
 
Apologies for the necropost, but I thought it better to revive this thread than start another. Is there any chance this will be implemented in a future version of XF? It's been a core feature of PHP for nearly 9 years and would go a long way toward simplifying template code under certain circumstances.
 
Apologies for the necropost, but I thought it better to revive this thread than start another. Is there any chance this will be implemented in a future version of XF? It's been a core feature of PHP for nearly 9 years and would go a long way toward simplifying template code under certain circumstances.
we need more people to upvote this. let's call upon the developers.
 
Back
Top Bottom