Home  >  Article  >  Backend Development  >  The difference between php require and include

The difference between php require and include

(*-*)浩
(*-*)浩Original
2019-10-12 10:11:342387browse

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)

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:

The difference between php require and include

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:

The difference between php require and include

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!

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
Previous article:php get day of weekNext article:php get day of week