Home > Article > Backend Development > The difference between include() and require() in PHP_PHP Tutorial
There are two ways to reference files: require and include. The two methods provide different usage flexibility.
Require is used as require("MyRequireFile.php");. This function is usually placed at the front of the PHP program. Before the PHP program is executed, it will first read in the file specified by require and make it a part of the PHP program web page. Commonly used functions can also be introduced into web pages in this way.
include is used like include("MyIncludeFile.php");. This function is generally placed in the processing part of flow control. The PHP program webpage only reads the include file when it reads it. In this way, the process of program execution can be simplified.
PS: The uses of the two are exactly the same, it doesn’t have to be which one is placed at the front and which one is placed in the middle. The most fundamental difference between them is the way they handle errors.
If there is an error in a require file, the program will interrupt execution and display a fatal error
If there is an error in including a file, the program will not end, but will continue to execute and display a warning error.