The difference between include and require in PHP

Source: Internet
Author: User
Require and include two ways to provide different use flexibility.

Require use methods such as require ("myrequirefile.php");. This function is usually placed at the front of the PHP program, and before the PHP program is executed, it is read into the file specified by require to make it a part of the PHP program's Web page. Commonly used functions, you can also use this method to introduce it into the Web page.

Include usage methods such as include ("myincludefile.php");. This function is generally placed in the processing section of the Process Control. The PHP Program page reads the include file when it is read. This way, you can simplify the process of executing the program.

1.incluce loading at time of use

2.require loads at the beginning

The 3._once suffix indicates that the load is not loaded

The PHP system has a pseudo-compile process when loading PHP programs, which can make the program run faster. But Incluce's documentation is still interpreted to perform

An error occurred in the include file and the main program continues to execute
The Require file went wrong and the main program stopped.
So the included file error has little impact on the system (such as interface files) with include, otherwise with require


The following documents also apply to require (). These two structures are exactly the same in addition to how they handle failures. The include () generates a warning and require () causes a fatal error. In other words, if you want to stop processing a page when you encounter a lost file, use require (). The include () is not the case and the script will continue to run. Also be sure to set the appropriate include_path.

The Require () function replaces itself with the contents of a given file, which occurs during the PHP engine's compile code, rather than during execution, and is not evaluated first, as in include (). The Require () function is used more in static elements, while the include () is more used in dynamic elements. Similar to Include_once (), require_once () will first check if the given code has been inserted, and if the code already exists, it will no longer be inserted.

  • Related Article

    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.