Feof method in PHP

Source: Internet
Author: User
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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.