Home > Article > Backend Development > The difference between php require and include
The difference between php include and require
In addition to the different ways of processing imported files, the biggest difference between include and require is :include will generate a warning when introducing a non-existing file and the script will continue to execute, while require will cause a fatal error and the script will stop executing. (Recommended learning: PHP video tutorial)
<?php include 'no.php'; echo '123'; ?>
If the no.php file does not exist, the echo '123' sentence can continue to be executed.
You see The situation may be similar to the following:
<?php require 'no.php'; echo '123'; ?>
If the no.php file does not exist, the echo '123' sentence will not be executed and will stop when require.
What you see may be similar to the following:
include() has the same function as require(), but there are some differences in usage. The difference is that include() is a conditional inclusion function, while require() is an unconditional inclusion function.
For example, in the following example, if the variable $somgthing is true, the file somefile will be included:
if($something){ include("somefile"); }
But no matter what value $something takes, the following code will include the file somefile Enter the file:
if($something){ require("somefile"); }
The above is the detailed content of The difference between php require and include. For more information, please follow other related articles on the PHP Chinese website!