Home > Article > Backend Development > Can php call other page methods?
PHP can call methods of other pages. Calling method: 1. Call with the include statement, which can insert the contents of the PHP file into another PHP file. The syntax is "include'filename'"; 2. Call with the require statement, the syntax is "require'filename'".
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
In PHP, you can use the include or require function instructions to introduce another page.
The include (or require) statement takes all text/code/tags present in the specified file and copies them to the file using the include statement.
Included files are useful if you need to reference the same PHP, HTML, or text on multiple pages of your website.
PHP include and require statements
With the include or require statement, you can insert the contents of a PHP file into another PHP file (before the server executes it).
The include and require statements are identical, except for error handling:
require will generate a fatal error (E_COMPILE_ERROR) and stop the script
include only generates warnings (E_WARNING) and the script continues
So if you wish to continue execution and output results to the user even if the include file is missing, then please Use include. Otherwise, in frameworks, CMS, or complex PHP application programming, always use require to reference key files to the execution flow. This helps improve application security and integrity in the event that a critical file is accidentally lost.
Including files saves a lot of work. This means you can create standard header, footer or menu files for all pages. Then, when the header needs updating, you simply update the header include file.
Grammar
include 'filename';
or
require 'filename';
Recommended study: "PHP Video Tutorial"
The above is the detailed content of Can php call other page methods?. For more information, please follow other related articles on the PHP Chinese website!