Bool
Feof ( Resource $ Handle ): Tests for end-of-file on a file pointer The original words above the PHP manual. I used this for convenience.
1 <? PHP
2 // If file can not be read or doesn' t exist fopen function returns false
3 $ File = @ Fopen ( " No_such_file " , " R " );
4
5 // False from fopen will issue warning and result in infinite loop here
6 While ( ! Feof ( $ File )){
7 }
8
9 Fclose ( $ File );
10 ?>
Indeed, this is relatively simple to use. However, if the above variable $ file is not a valid file pointer or has been disabled by fclose.
InProgramThe sixth line will generate a Waring, concurrent life cycle.
Why?
The reason is
ReturnsTrueIf the file pointer is at EOF or an error occurs (including socket timeout); Otherwise returnsFalse.
Therefore, for the sake of security, it is best to use the aboveCodeWhen you add a judgment, is_resource is relatively safe.