PHP file inclusion statements include and include

Source: Internet
Author: User
1. The include () include (pathtofilename) include () statement will include a file at the location where it is called. A file contains the same content as the data copied to the file where the statement is located. Parentheses can be ignored when include () is used. You can execute the include () statement according to the conditions. Entries

1. The include () include (/path/to/filename) include () statement will include a file at the called location. A file contains the same content as the data copied to the file where the statement is located. Parentheses can be ignored when include () is used. You can execute the include () statement according to the conditions. Entries

1. include () include (/path/to/filename) include ()StatementIt will be at the location where it is calledIncludeOneFile.IncludeOneFileAndStatementLocation replication settingsFile. Parentheses can be ignored when include () is used. You can execute include () according to the conditions ()Statement. In the conditionStatementThe use of include () has a strange phenomenon, which must be enclosed inStatementBlock in braces, or use otherStatementEnclose.

2. The include_once () include_once (filename) include_once () function has the same role as include, but it will first verify whetherIncludeTheFile. IfIncludeThen, revoke de_once is no longer executed. Otherwise, it mustIncludeTheFile. This is the same as include.

3. require () require (filename) require () is largely the same as include.FileIncludeTo the location where the require call is located. There are two important differences between require and include. First, regardless of the location of requireFileAllIncludeTo the script where require appears. For example, even if require is placed in an ifStatement, StillIncludeSpecifyFile. The second important difference is that when a require error occurs, the script stops running, and the script continues to run when the include is used.

4. As the website grows, require_once () require_once (filename) may repeatIncludeSomeFile. This may not be a problem, but it has been modified.IncludeFileAfter the variableIncludeOriginalFileIf it is overwritten, this situation may not be desired. Another problem may occur:IncludeFileConflict between letters. Use require_once to solve these problems. Ensure that the require_once FunctionFileOnlyIncludeOnce. After encountering require_once, try again laterIncludeSameFileWill be ignored.

Differences:

The difference between include () and require:

They all load the specified script and run the loaded script.

Differences:

Inlucde () will continue to be executed if loading fails,

Require () If LoadFileIf the loading fails, an error is reported and the loading fails.

Difference between include_once () and require_once:

They are all loading and running the following script

Differences:

Include_once is importedFileIf the following code is not saved, the execution will continue. The require_once import will not be stoppedFileIf it does not exist, the program will end. Generally, the HTML of the program is not affected.FileAnd so on.FileConfigurationFileAnd so on.

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.