#28273 [NEW]: feof() doesn't return TRUE when invalid file handle is passed to it

From: Date: Tue, 04 May 2004 13:58:53 +0000
Subject: #28273 [NEW]: feof() doesn't return TRUE when invalid file handle is passed to it
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-59206@lists.php.net to get a copy of this message
From: mikeboulet at newfangled dot com Operating system: Redhat 7.2 or Redhat AS 2.1 PHP version: 4.3.4 PHP Bug Type: Filesystem function related Bug description: feof() doesn't return TRUE when invalid file handle is passed to it Description: ------------ 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. Reproduce code: --------------- <?php $fp = fopen( 't.txt', 'r' ); while( !feof( $fp ) ) { print fgets( $fp ); } fclose( $fp ); ?> Expected result: ---------------- 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. Actual result: -------------- Inifinite loop -- Edit bug report at http://bugs.php.net/?id=28273&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28273&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28273&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28273&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28273&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28273&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28273&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28273&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28273&r=support Expected behavior: http://bugs.php.net/fix.php?id=28273&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28273&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28273&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28273&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28273&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28273&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28273&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28273&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28273&r=float

« previous php.bugs (#59206) next »