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.