Home > Backend Development > PHP Problem > The difference between php require and include

The difference between php require and include

(*-*)浩
Release: 2023-02-26 12:02:02
Original
2595 people have browsed it

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 &#39;no.php&#39;;
  echo &#39;123&#39;;
?>
Copy after login

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

<?php
require &#39;no.php&#39;;
echo &#39;123&#39;;
?>
Copy after login

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");
}
Copy after login

But no matter what value $something takes, the following code will include the file somefile Enter the file:

if($something){
require("somefile");
}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template