Use of phprequire_once and difference with require

Source: Internet
Author: User
: This article mainly introduces the use of phprequire_once and the difference between phprequire_once and require. For more information about PHP tutorials, see. Differences:

Require_once only loads the same file once, and require loads the file multiple times.

I think there are still some doubts about the same little white as me. So we guess: if 456. php has introduced 123.php, the file test_require.php has introduced "456. php" and "123. php ". If the require method is used, 123. php will be introduced twice in test_require.php, and the require_once method 123. php will be introduced once. So let's do the experiment!

1. require method

123. php content is as follows:

 

456. php content is as follows:

  The content of test_require.php is as follows:

   Run test_require.php and the result is as follows:


II. require_once method

123. php content remains unchanged. 456. php and test_require.php change the require_once method. The content is as follows:

// 456.php
    Run test_require.php and the result is as follows:

III. mixed errors

If you use the require method in 456. php and the require_once method, require_once will become invalid. The code for the three files is as follows:

// 123.php
     The running result is as follows:


Summary: As we guess, the require_once method does not load the same file multiple times. However, mixing with require will invalidate the require_once method.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces the use of php require_once and the difference with require, including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.