Differences between include and require

Source: Internet
Author: User
Provides various official and user-released code examples and code reference. You are welcome to share the following learning files:
Include/include_once
Require/require_once
Both Include and require introduce a page to the current page.
How to Understand "Introduction ".

It is equivalent to replacing include/require with all the code of the contained file.
It is the same as writing the code in the include statement directly.

Require is used to introduce a file to the current file.
Similar to include.

Difference between Include and require
A: If the introduced file does not exist, include tries to continue and reports a warning
(If you don't mind whether or not the previous content is included and all subsequent content needs to be executed, use include)
If the file introduced by require does not exist, the system reports a fatal error and does not continue executing the request.
(If the previous content must be included before continuing to execute the code, use require)

========================================================== ======================
Difference between Include/require and include_once/require_once
_ Once automatically determines whether the file has been introduced. If yes, it will not be executed repeatedly.
That is, ensure that the contained file can be introduced only once.
(If the contained file contains a defined function, the contained file can only be contained once. If it is included multiple times, a function redefinition error will occur, php does not run function redefinition, and a fatal error may occur, and the code will not run later)
========================================================== ====================
Some files cannot be contained multiple times?
You can use _ once to control,
However, if the document design is more standardized, it is guaranteed that there will be no inclusion errors for multiple times,
In this case, we recommend that you use include
Because include_once needs to check whether it has been included before, the efficiency is not as high as include.

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.