|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-05-04 15:58 UTC] mikeboulet at newfangled dot com
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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 00:00:02 2025 UTC |
Works fine with latest CVS: <?php $fp = @fopen('/etc/passwd-', 'r' ); var_dump($fp, feof( $fp )); ?> prints bool(false) twice as it should.