note 31567 added to function.feof

From: Date: Sat, 26 Apr 2003 11:16:02 +0000
Subject: note 31567 added to function.feof
Groups: php.notes 
Request: Send a blank email to php-notes+get-47132@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.feof.php http://master.php.net/manage/user-notes.php?action=edit+31567 http://master.php.net/manage/user-notes.php?action=delete+31567 http://master.php.net/manage/user-notes.php?action=reject+31567

« previous php.notes (#47132) next »