Home  >  Article  >  Backend Development  >  What are the differences between php require and include?

What are the differences between php require and include?

烟雨青岚
烟雨青岚Original
2020-06-29 13:41:373364browse

The difference between require and include in PHP is: when the file to be included does not exist, include will generate a warning (Warning), and the program following the statement will continue to execute; while require will generate a fatal error ( Fatal error), the program terminates.

What are the differences between php require and include?

include If two files are imported with the same function name, a redefinition error will occur. This error can be avoided by using include_once. Generally, _once is used more often.

The difference between include and require

When the file to be included does not exist, include generates a warning (Warning), and the program following the statement will continue to execute ; and require results in a fatal error (Fatal error) and the program terminates.

include_once and require_once

should be used when the same file may be included more than once during script execution and you want to ensure that it is only included Once to avoid problems such as function redefinition and variable reassignment.

1.include is loaded when used. This function is usually placed in the processing section of the process control.

2.require is loaded at the beginning. This function is usually placed in The first

3._once suffix of the PHP program indicates that the loaded one is not loaded

Recommended tutorial: "php tutorial"

The above is the detailed content of What are the differences 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