note 17868 deleted from function.fopen by sniper
| From: | sniper@php.net | Date: | Wed, 28 Dec 2005 11:02:13 +0000 |
| Subject: | note 17868 deleted from function.fopen by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100841@lists.php.net to get a copy of this message | ||
Note Submitter: slevy1 at pipeline.com
----
Attn Perl Programmers:
If you are used to writing script like
do something || die("no can do");
note that in php || has a higher precedence than =
So, don't write:
$h = fopen("$filename", "r") || die("cannot open $filename");
b/c this will overwrite the file ptr!
Now, or has a lower precedence than || and is also lower than =
So, you may write:
$h = fopen("$filename","r") or die("cannot open $filename");
However, you may avoid the entire issue with code like this:
$h = fopen("$filename","r");
if (!$h) {
die("unable to open $filename");
}