note 42130 rejected from function.feof by didou

From: Date: Wed, 03 Jan 2007 01:46:12 +0000
Subject: note 42130 rejected from function.feof by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-121218@lists.php.net to get a copy of this message
Note Submitter: mark at newfangled dot com ---- 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.

« previous php.notes (#121218) next »