Is it safe to use constructs like these in PHP:
$filename = $file['filename1'] || $file['filename2'];
I have a background in JS and this is safe to use since we can trust truthy/falsey values. However my colleague is used to constructs utilizing isset:
$filename = 'filename'. (isset($file['filename2']) ? '2' : '1');
Which to me seem a little verbose.
I found an article on phabricator.com which outlines the different truthy/falsey values in PHP and offers this table:
VALUE if() empty() isset()
null false true false
0 false true true
0.0 false true true
"0" false true true
"" false true true
false false true true
array() false true true
EVERYTHING ELSE true false true
I would appreciate anyone giving me insights in this matter.
||and other comparative operators in php will return a BOOLEAN value, it will not act like it does in javascript.