I've seen this a lot: $fp = fopen($filepath, "w") or die();
But I can't seem to find any real documentation on this "or" syntax. It's obvious enough what it does, but can I use it anywhere? And must it be followed by die()
? Are there any caveats to using or
when you could use something like
if (file_exists($filepath))
$fp = fopen($filepath,"r");
else
myErrMessage();
I know it seems like a silly question, but I can't find any hard and fast rules for this. Thanks.
or
can be used to combine expressions, not statements. And it's sometimes useful because of its lower operator precedence (in comparison to the assignment). Btw, your if blocks are missing curly braces. Don't look for syntax shortcuts until you've mastered that. – Apo