[PHP syntax] The difference between php include, require, include_once, require_once

1. The difference between include() and require():

When include() introduces a file, if an error is encountered, it will prompt an error and continue to execute; when an error is encountered when a file is imported by require(), an error will also be prompted but the program will be terminated.

The require() statement is generally placed at the top of the php script page. Before php is executed, it first reads the file introduced by require(), and the content of the file will become part of the script. Once an error occurs, the program will exit immediately.

The include() statement is generally introduced when it is used, so it is usually placed in the processing section of the process control, and the file will be included only when the php script is executed to it.

That is, require() is a preloading mechanism, located at the front of the script, and all files that may be used are introduced at the beginning; include() is ready-to-use and loaded, and the location is flexible.


2. The difference between include(), require() and include_once() and require_once():

When include() and require() are executed, the file is included, and the imported files will not be compared and judged, and repeated inclusion may occur; while include_once() and require_once() will first determine whether the file is included when it is included.

It has already been included. If it has been included, the file is no longer included. This way of importing files can save resources and avoid errors of repeated definitions.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325434095&siteId=291194637