Home  >  Article  >  Backend Development  >  Detailed explanation of php require usage

Detailed explanation of php require usage

藏色散人
藏色散人Original
2020-07-08 10:26:4114741browse

php require is a built-in function of PHP, which is used to introduce or include external PHP files. The working principle is that when the own PHP file is executed, the contents of the external file will be included in the own PHP file; When an error occurs in the included external file, the system will throw an error prompt and stop the execution of the php file.

Detailed explanation of php require usage

php require usage details

require() is a built-in function of php, which is used to introduce or include external php document.

Working principle: When the own PHP file is executed, the contents of the external file will be included in the own PHP file; when an error occurs in the included external file, the system will throw an error prompt, and Stop the execution of the php file.

Note: When using require, if there is an error in a file, the program will interrupt execution and display a fatal error.

For example, there are two files: cl.php and ts.php. If ts.php needs to use the functions in the cl.php file, it needs to be introduced or included in ts.php. The example is as follows:

cl.php

<?php
function  show(){
    echo "cl.php文件中的show方法被调用了!";
     
}
?>

ts.php

<?php
require &#39;cl.php&#39;;
show();
?>

Running result:

Detailed explanation of php require usage

For more related knowledge, please Visit PHP Chinese website!

The above is the detailed content of Detailed explanation of php require usage. 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