What's the difference between include require in PHP

Source: Internet
Author: User
1. Include generates a warning when the file is not saved and the script will continue to execute.

Require causes a fatal error and the script stops executing.

2, include () is a conditional include function, and require () is an unconditional include function.

3. Include has a return value, and require has no

4. Include () files that need to be referenced every time they are executed are read and evaluated.
Require () executes a file that needs to be referenced only once (the Require () statement is actually replaced with the file content to be referenced when executing)

You can see that if you have code that contains one of these directives and code that might execute multiple times, using require () is a high efficiency,
If you read different files each time you execute the code or have loops that pass through a set of file iterations, use the Include (),


Require usually use the method, this function is usually placed in the front of the PHP program, the PHP program before execution, will be read into the require specified by the introduction of the file, so that it becomes a part of the PHP program page. Commonly used functions, you can also use this method to introduce it into the Web page.

Include typically uses methods, which are generally placed in the processing part of the process control. The PHP Program page reads the include file before it is read in. This way, you can simplify the process of executing the program


  • Incluce load when used

  • Require is loaded at the beginning

  • The _once suffix indicates that the load is not loaded

  • 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.