About require/include in PHP

Source: Internet
Author: User
Most of my impressions about the require and include keywords are that they are unconditionally inserted during pseudo-compilation, while the latter is interpreted and executed during runtime. The problem is as follows: 1. If the file to be introduced is determined at runtime, such as require $ file; and include $ file, then this... requireAnd includeThe biggest difference in my impression is that the former is unconditional insert during pseudo-compilation, while the latter is interpreted and executed during runtime.
The problem is as follows:
1. If the file to be introduced is determined at runtime, for example require $file;And include $fileIn this case, what is the difference between the two actions?
2. I use these two keywords as the C Language #includeBut in actual use, for example $a=require('b.php');In b.phpShould be written Instead of writing directly What logic is this?

Finally, thank you for your feedback.

Reply content:

AboutrequireAndincludeThe biggest difference in my impression is that the former is unconditional insert during pseudo-compilation, while the latter is interpreted and executed during runtime.
The problem is as follows:
1. If the file to be introduced is determined at runtime, for examplerequire $file;Andinclude $fileIn this case, what is the difference between the two actions?
2. I use these two keywords as the C Language#includeBut in actual use, for example$a=require('b.php');Inb.phpShould be written Instead of writing directly What logic is this?

Finally, thank you for your feedback.

The first question is explained upstairs, and the second question is explained.
// B. php
'Php']; // No return require received
// A. php
$ A = require ('B. php'); // $ a is ['sf' => 'php']

A fatal error occurs when a request fails to be referenced.

The difference between require and include is that when the referenced file does not exist, the error levels of the two are different. Include is only a warning, and require is a fatal error. For more information, see the official php documentation.

If an error exists in a file in require, the program will be interrupted and a fatal error will be displayed.
If an include file has an error, the program will not be in the middle, but will continue to execute and display a warning error.
Also, include has a return value, but require does not.

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.