PHP 5.3 has an abbreviated operator ?: ::
$foo = $bar ?: $baz;
What does $bar assign if it is not an empty value (I donβt know how it would be otherwise in PHP from Perl), otherwise $baz is the same as in Perl and older versions of PHP:
$foo = $bar ? $bar : $baz;
But PHP does not have a complex assignment operator for this (i.e. no equivalent to Perl ||= ).
In addition, PHP will make noise if $bar not set, unless you turn off notifications. There is also a semantic difference between isset() and empty() . The first returns false if the variable does not exist or is set to NULL . The latter returns true if it does not exist, or set to 0 , '' , false or NULL .
BoltClock May 12 '11 at 1:52 2011-05-12 01:52
source share