note 31567 deleted from function.feof by didou
| From: | didou@php.net | Date: | Fri, 11 Jul 2003 12:41:27 +0000 |
| Subject: | note 31567 deleted from function.feof by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51907@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Please note that this function "returns TRUE if [...] an error occurs". I don't quite
understand why it does, but it means you must check every file pointer before using feof() inside a
loop.
$fp = fopen($filename, 'r');
while (!feof($fp)) {
// ...
}
If the file doesn't exist, $fp, won't be a valid resource but feof() will retrun TRUE
nonetheless, which means you will be caught in an endless loop.
$fp = fopen($filename, 'r');
if (!is_resource($fp)) {
// ...
} else {
while (!feof($fp)) {
// ...
}
}
Very annoying.