Include and require in PHP

Source: Internet
Author: User

1.include statements


Use the Include statement to tell PHP to extract a specific file and load its entire contents
    1. 1 <? PHP 2 inlude "fileinfo.php"; 3 4 // add additional code here 5 ?>
2.include_once StatementsEach time you use the INCLUDE statement, it will re-import the requested file, even if the file has already been imported. For example, assume that fileinfo.phpThe file contains many functions, we use the Include statement to import him into an existing file, and then we import a fileinfo.phpThe files, through nesting, we've put fileinfo.phpThe file was imported two times, which produces an error because we tried to define a variable or function with the same name multiple times. To prevent this from happening, we use the include_once statement instead of the include statement
    1. 1 <? PHP 2 include_once "fileinfo.php"; 3 4 // add additional code here 5 ?>
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.
    1. 1 <? PHP 2 require_once "fileinfo.php"; 3 4 // add additional code here 5 ?>
in general, we should insist on using require_once statements.

Include and require in PHP

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.