Difference between include and require

Source: Internet
Author: User

I used to think about this issue when I was writing a program. Today I just saw this issue, so I will sort it out and summarize it!

These two structures are identical except for how to handle failures. Include () generates a warning and require () causes a fatal error. In other words, if you want to stop processing the page when a file is lost, use require (). Include () is not the case, the script will continue to run

Include or not.

Require must have

When an include error occurs, an error is returned but the execution continues.

A fatal error occurs when a require error occurs.

 

---------------------------------------------------------------------------------

  • Require ():If the file does not exist, a fatal error is reported. The script stops running.
  • Include ():If the file does not exist, a warning is provided, but the script continues to run.

Note:
If the include () file does not exist, the script continues to run.Before PHP 4.3.5, this is often overlooked.

We recommend that you use require_once () and include_once () to check whether the file contains duplicates.

Bytes --------------------------------------------------------------------------------------

Another difference is described as follows:
As long as there is require, it will always contain the specified file;
If the program does not execute include, the specified file will not be included. For example, if the if condition is not true, use include in the IF statement.

(The following is a detailed description of the Difference)

Note:The following rules apply before PHP 4.0.2:Require ()It will always try to read the target file, even if its row is not executed at all. Condition statements are not affected.Require (). However, ifRequire ()If the row is not executed, the code in the target file is not executed. Similarly, the loop structure does not affectRequire (). Although the Code contained in the target file is still the subject of a loopRequire ()It only runs once.

03. 13

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.