note 42130 added to function.feof

From: Date: Tue, 04 May 2004 14:39:31 +0000
Subject: note 42130 added to function.feof
Groups: php.notes 
Request: Send a blank email to php-notes+get-69207@lists.php.net to get a copy of this message
When a fopen() is done on a file that has permissions that are set to not allow the current process user to read it or the file doesn't exist it returns false. This is expected. The problem is when feof() is fed the invalid handle it doesn't return TRUE() thus creating an infinite loop in the following code example. <?php $fp = fopen( 't.txt', 'r' ); while( !feof( $fp ) ) { print fgets( $fp ); } fclose( $fp ); ?> feof() would return TRUE to cancel the loop and the script would end. There would of course be warnings because of the invalid file handle, but that is expected. There should be better error handling on the developers part and catch the invalid file handle, but I would expect the file functions to handle this situation accordingly. ---- Manual Page -- http://www.php.net/manual/en/function.feof.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42130 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42130&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42130&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69207) next »