I've been reviewing a lot of PHP code lately and I keep coming across situations like this:
function () {
$var = '';
if ( ... ) {
$var = '1';
}
echo $var;
}
An empty variable is declared and then later defined.
Is there a reason behind this?
The only reason I can think of for doing this is just to make sure $var starts out as empty in case it's previously defined.
$varwould else resolve to NULL; with a Notice (which this approach is often used for to eschew).echo @$var;this will by pass the E_NOTICE