I used to think about this issue when I was writing a program. Today I just saw this issue, so I will sort it out and summarize it!
These two structures are identical except for how to handle failures. Include () generates a warning and require () causes a fatal error. In other words, if you want to stop processing the page when a file is lost, use require (). Include () is not the case, the script will continue to run
Include or not.
Require must have
When an include error occurs, an error is returned but the execution continues.
A fatal error occurs when a require error occurs.
---------------------------------------------------------------------------------
- Require ():If the file does not exist, a fatal error is reported. The script stops running.
- Include ():If the file does not exist, a warning is provided, but the script continues to run.
Note:
If the include () file does not exist, the script continues to run.Before PHP 4.3.5, this is often overlooked.
We recommend that you use require_once () and include_once () to check whether the file contains duplicates.
Bytes --------------------------------------------------------------------------------------
Another difference is described as follows:
As long as there is require, it will always contain the specified file;
If the program does not execute include, the specified file will not be included. For example, if the if condition is not true, use include in the IF statement.
(The following is a detailed description of the Difference)
Note:The following rules apply before PHP 4.0.2:Require ()It will always try to read the target file, even if its row is not executed at all. Condition statements are not affected.Require (). However, ifRequire ()If the row is not executed, the code in the target file is not executed. Similarly, the loop structure does not affectRequire (). Although the Code contained in the target file is still the subject of a loopRequire ()It only runs once.
03. 13