Similar points:
First of all, include(), include_once() and require(), require_once() are all used to include and run specified files, and the included files are exactly the same in structure when executed.
For example: include("file.php");
include_once("file.php");
require("file.php");
require_once("file.php");
Differences :
1. Different usage methods
include() and include_once() are generally placed in PHP process control programs.
require() and require_once() are usually placed at the front of the PHP program. The file specified by require() will be read in before the PHP program is executed.
2. Different error methods are reported during execution
When include() and include_once() encounter that the included file does not exist or an error occurs, the execution will continue and a warning error will be displayed, with a return value.
When require() and require_once() encounter that the included file does not exist or an error occurs, they will stop execution and report an error, display a fatal error, and have no return value. The difference between
include(), require() and include_once(), require_once():
include(), require(): When the same file is included multiple times, the same file content will be imported repeatedly.
include_once(), require_once(): Will first check whether the target file has been imported before. If so, the same file will not be imported again.
That’s all for now, let’s learn together!
The above introduces the similarities and differences between include, include_once and require, require_once, including the content of require_once. I hope it will be helpful to friends who are interested in PHP tutorials.