Detailed explanation of php require usage

藏色散人
Release: 2023-03-02 07:46:02
Original
14782 people have browsed it

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方法被调用了!";
     
}
?>
Copy after login

ts.php

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

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!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!