PHP upgrade-include (), require (), include

Source: Internet
Author: User
PHP upgrade-includeInclude and require statements are used to insert useful code into other files in the execution stream. Include is very similar to require, except for the difference in error handling. Require will generate a fatal error (E_COMPILE_ERROR) and stop the script. include will only generate a warning (E_WARNING), and the script will continue. 1. Require

PHP upgrade-include Include and require statements are used to insert useful code into other files in the execution stream. Include is very similar to require, except for the difference in error handling. Require will generate a fatal error (E_COMPILE_ERROR) and stop the script. include will only generate a warning (E_WARNING), and the script will continue. 1. Require

PHP upgrade-include

The Include and require statements are used to insert useful code into other files in the execution stream.

Include is similar to require except for differences in error handling.

Require will generate a fatal error (E_COMPILE_ERROR) and stop the script. include will only generate a warning (E_WARNING), and the script will continue.

1. The differences between Require, require_once, include, and include_once.

Require (): contains and runs the specified file.

Include (): Include and run the specified file.

Require_once (): contains and runs the specified file. If the target file already exists, it is not included. It is similar to the require () statement.

Include_once (): contains and runs the specified file. If the target file already exists, it is not included. It is similar to include.

2. Difference Between Require () and require_once ()

If the code in the contained file is already included, it is not included again. Require_once () is applicable when a file may be contained multiple times during script execution, so that it is included only once to avoid function redefinition and variable re-assignment.

3. Differences between Include and include _ once ()

If the code in the contained file is already included, it is not included again. Require_once () is applicable when a file may be contained multiple times during script execution, so that it is included only once to avoid function redefinition and variable re-assignment.

4. Difference Between Require_once () and include_once ()

It should be noted that the behavior of require_once () and include_once () in case of an error is completely different. include will generate a warning, and the subsequent code will continue to be executed, while require_once () this leads to a fatal error. Stop the script and continue running.

Applicability:

Contains any number of files. If an error occurs, use require () to stop the script ();

Contains any number of files. If an error occurs and does not stop, use include ();

If the script file is stopped when an error occurs, use require_once ();

Contains files once. If an error occurs and does not stop, use include_once ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.