PHP files contain statements include, include_once, require, require_once

Source: Internet
Author: User

1. The include () include (/path/to/filename) include () statement will contain a file at the location where it was called. Contains a file that has the same content as the data in which the file was copied at the location of the statement. Parentheses can be ignored when using include (). The include () statement can be executed according to the criteria. Using the include () in a conditional statement has a strange phenomenon, which must be enclosed in a statement block brace, or surrounded by other statement bracketing.

2, the include_once () include_once (filename) include_once () function works the same as include, but it first verifies that the file is already included. If it is already included, Include_once is no longer executed. Otherwise, you must include the file. Except this is exactly the same as the include.

3, require () require (filename) require () is, to a large extent, the same as include, which is to include a template file in the location where the require call sits. There are two important differences between require and include. First, the file will be included in the script that appears require, regardless of the location of the require. For example, even if the require is placed in an if statement that evaluates to FALSE, the specified file will still be included. The second important difference is that when a require error occurs, the script stops running, and the script continues to execute with include.

4, require_once () require_once (filename) as the site grows larger, there may be duplicates containing certain files. This may not be a problem, but once you have modified the variables for the included files, you may not want this to happen because they are overwritten by the subsequent inclusion of the original file. There may also be another problem, which is the conflict of function names in the included files. Use require_once to solve these problems. The Require_once function ensures that the file is included only once. After encountering require_once, the subsequent attempt to include the same file is ignored.

Difference:

The difference between include () and require ():

They both load the specified script and run the loaded script

Difference:

INLUCDE () If the load failure continues to execute,

Require () If the load file does not exist, it will be error-filled and upright

The difference between include_once () and require_once ():

They all load up and run the following script

Difference:

Include_once  Even if the imported file does not exist, the following code will continue to execute. Does not stop require_once  the imported file does not exist, the program ends. In general, the HTML files that do not affect the program are imported with include_once, such as the library file configuration file, and so on using require_once.

PHP files contain statements include, include_once, require, require_once

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.