Difference Between include and require in PHP

Source: Internet
Author: User
Tags flock
The difference between include and require in PHP is the difference between include and require. In fact, there is no big difference between the two. if the file to be included does not exist, include prompts notice and continues to execute the following statement, require prompts a fatal error and exits. According to the test, on the win32 Platform, they are all included first and then executed. Therefore, it is recommended that there be no include or require statements in the contained files, which will cause directory confusion. Or the difference between include and require in PHP

The difference between include and require is actually not much different. if the file to be included does not exist, include prompts notice and continues to execute the following statement. require prompts a fatal error and exits.

According to the test, on the win32 Platform, they are all included first and then executed. Therefore, it is recommended that there be no include or require statements in the contained files, which will cause directory confusion.

Maybe * The situation is different in nux and has not been tested yet. If you do not want to include a file multiple times, you can use include_once or require_once # to read and write the file data:

1 function r ($ file_name) {2 $ filenum = @ fopen ($ file_name, "r"); 3 @ flock ($ filenum, LOCK_SH ); 4 $ file_data = @ fread ($ filenum, filesize ($ file_name); 5 @ fclose ($ filenum); 6 return $ file_data; 7} 8 function w ($ file_name, $ data, $ method = "w") {9 $ filenum = @ fopen ($ file_name, $ method); 10 flock ($ filenum, LOCK_EX ); 11 $ file_data = fwrite ($ filenum, $ data); 12 fclose ($ filenum); 13 return $ file_data; 14}



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.