The basic difference between require and include in PHP is that in general PHP development, the functions of require and include are roughly the same, but there are some differences. please refer to the following description. The basic difference between require and include in PHP is that in general PHP development, the functions of require and include are roughly the same, but there are some differences. please refer to the following description.
First point: Require () and include () are identical in all aspects except 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 () to directly stop the script. This is not the case with include (). The script will continue to run, but a Notice-level error will be thrown. Make sure that the appropriate include_path is set.
That is to say, when parsing the program, it reads the require file instead of the file to be parsed. if you cannot read the file to be require, you cannot perform the next action. Therefore, improper inclusion may lead to program files. it is better to use require.
Second point: Require () will contain files in any way, and include () can selectively include:
If (FALSE ){ Require ('A. php '); } If (FALSE ){ Include ('B. php '); } ?> |
For example, in the above code, a. php will be included, and B. php will not. Require is similar to a pre-scan. during program execution, The require file will be executed only once, whether in the function or outside the function. The include statement calls the file once every execution. that is, after this execution, the file will be executed again next time. You should understand the difference :)
You can also see the difference between require_once and include_once.
The require_once () statement includes and runs the specified file during script execution. This behavior is similar to the require () statement. The only difference is that if the code in the file has been included, it will not be included again.
The include_once () statement includes and runs the specified file during script execution. This behavior is similar to the include () statement. The only difference is that if the code in the file has been included, it will not be included again. As the statement name implies, it will only be included once.