Difference Between include and require in php

Source: Internet
Author: User
The require and include methods provide different elasticity. For example, require (& amp; quot; MyRequireFile. php & amp; quot ;);. This function is usually placed at the beginning of the PHP program. before the PHP program is executed, it will first read the file specified by require to make it into the PHP program webpage... the require and include methods provide different elasticity.

The use of require is as follows: require ("MyRequireFile. php ");. This function is usually placed at the beginning of the PHP program. before the PHP program is executed, it will first read the file specified by require to make it a part of the PHP program webpage. This method can also be used to introduce a commonly used function to a webpage.

Include usage methods such as include ("mydomaindefile. php ");. This function is generally placed in the process section of process control. The include file is read on the PHP webpage. In this way, you can simplify the process during program execution.

1. incluce loaded when used

2. require load at the beginning

3. the _ once suffix indicates that the loaded files are not loaded.

The php System has a pseudo-compilation process when loading the php program, which can speed up the program running. However, the CE documentation is still interpreted.

An error occurred in the include file. the main program continues to execute.
The require file has an error and the main program has stopped.
Therefore, if the error of the contained file does not affect the system much (such as the interface file), use include. Otherwise, use require.


The following documents also apply to require (). 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 (). This is not the case with include (). The script will continue to run. Make sure that the appropriate include_path is set.

The require () function replaces itself with the content of a given file, which occurs during PHP engine code compilation rather than during execution, unlike include () the calculation is performed first. The require () function is more used in static elements, while the include () function is more used in dynamic elements. Similar to include_once (), require_once () first checks whether the given code has been inserted. if the code already exists, it is no longer inserted.

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.