What does require mean in php

青灯夜游
Release: 2023-03-10 09:30:01
Original
4959 people have browsed it

In PHP, require means "introducing a file" and is generally used to "include and run the specified file", that is, insert useful code written in other files into the execution flow. The syntax "require ' file name'". When the require statement introduces a file, if an error is encountered, a prompt will be given and the subsequent code will stop running.

What does require mean in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

require statement can include and run the specified file, use Used to insert useful code written in other files into the execution flow.

For require(), the file is processed only once (in fact, the file content replaces the require() statement). This means that if the code is likely to be executed multiple times, it is more efficient to use require().

require() is used like:

require("myfile.php")
require "myfile.php"
Copy after login

Description: The require() statement is a language structure, not a real function. It can be like other language structures in php Same, for example, echo() can use echo("ab") form, or echo "abc" form can be used to output the string abc. The require() statement can also add parameters directly without parentheses.

This statement is usually placed at the beginning of the PHP script program. Before the PHP program is executed, it will first read the file introduced by the require() statement, making it a part of the PHP script file.

Error reporting

require When an error occurs, an E_COMPILE_ERROR level error is generated; that is, when an error is encountered when importing a file, a prompt will be given and the subsequent execution will stop. code.

Create a new test-require.php file and write the following code (do not have a file named test-nothing.php in the directory.)

<?php
require &#39;test-nothing.php&#39;;
echo &#39;abc&#39;;
?>
Copy after login

Browse http://localhost/ test-require.php, because the test-nothing.php file was not found, we saw the error message, but abc was not displayed below the error message. What you saw may be similar to the following:

Warning: require(test-nothing.php) [function.require]: failed to open stream: No such file or directory in D:\www\test-require.php on line 2
Fatal error: require() [function.require]: Failed opening required &#39;test-nothing&#39; (include_path=&#39;.;C:\php5\pear&#39;) in D:\www\test-require.php on line 2
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does require mean in php. 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!