Skip to content
Advertisement

Undefined variables in PHP template

I use PHP as a template language in my view layer, Is it possible to make the following a little cleaner and more concise?

JavaScript

Unfortunately, we can not even define a function for that:

JavaScript

Advertisement

Answer

Using @ operator is the shortest alternative.

JavaScript

Since PHP 7 you can also use the ?? operator.

JavaScript

Which does exactly what the @ operator does, though a bit longer.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement