Pro Tip Alternative Assignment

PHP Alternative assignment

In JavaScript you can use the following sintax:

var foo = this.bar || 'default';

In PHP 5.3 the equivalent syntax would be a imaginative use of the ternary operator.

$foo = $bar ?: 'default';

If you want to use the logical or operator, || you would have to take a roundabout.

$foo || $foo = 'default';