Simply talk about the include, include_once, require, and require_once statements in PHP, requireonceinclude_php tutorial

Source: Internet
Author: User

Simply talk about the include, include_once, require, and require_once statements in PHP, Requireonceinclude


1.include statements

Use the Include statement to tell PHP to extract a specific file and load its entire contents

<?phpinlude "fileinfo.php";//Add additional code here?>

2.include_once statements

Each time you use the INCLUDE statement, it will re-import the requested file, even if the file has already been imported. For example Assuming that the fileinfo.php file contains many functions, we use the Include statement to import him into an existing file, and then we import a file that contains fileinfo.php, and we have imported the fileinfo.php file two times through nesting, which produces an error because we tried to Define a variable or function with the same name. To prevent this from happening, we use the include_once statement instead of the include statement

<?phpinclude_once "fileinfo.php";//Add additional code here?>

At this point, if you encounter another include or include_once statement in the same file, PHP checks to see if it has been imported and, if so, ignores it.

3.require and Require_once statements

The potential problem with using the Include and include_once statements is that PHP will only attempt to import the file that was requested for import, even if the file is not found and the program will still execute.
When we absolutely need to import a file, using the Require statement, the same reason for using the require_once statement, is no longer mentioned in this.

<?phprequire_once "fileinfo.php";//Add additional code here?>

In general, we should insist on using require_once statements.

http://www.bkjia.com/PHPjc/1123848.html www.bkjia.com true http://www.bkjia.com/PHPjc/1123848.html techarticle simply talk about the include, include_once, require, and require_once statements in PHP, requireonceinclude 1.include statements Use the Include statement to tell PHP to extract specific files and load ...

  • Related Article

    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.