Any more concise way to set default values?

default-value, php, variable-assignment, variables

Solution

Here is a shorter syntax:

isset($v) || $v="default value";

Problem

Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: expr3 returns expr1 if expr1 evaluates to TRUE, and expr3 otherwise. Is there any better or more concise way than following code to set default value of variables? ``` $v = isset($v) ? $v : "default value"; ```

Original source

Related problems