Home  >  Article  >  Backend Development  >  The difference between include() and require() in PHP_PHP Tutorial

The difference between include() and require() in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:55:00934browse

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364520.htmlTechArticleThere are two ways to reference files: require and include. The two methods provide different usage flexibility. The usage method of require is as require(MyRequireFile.php);. This function is usually placed...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn