The use of PHP require_once and the difference from require

Source: Internet
Author: User
difference:

Require_once will only load the same file once, require will load multiple times.

I believe that the same as my small white or some doubts it. So we assume: if 456.php introduced 123.php, now file test_require.php introduced "456.php" and "123.php". If the Require method is used, then in test_require.php, 123.php is introduced 2 times, and 123.php is introduced once using the Require_once method. Then let's do the experiment!

First, Require method

The contents of 123.php are as follows:

 

The 456.php content is as follows:

 
   Require ("123.php");  echo "456\n";
The contents of test_require.php are as follows:

  Run test_require.php to get the result as follows:


Second, require_once method

123.php content does not change. 456.php and test_require.php Change the Require_once method. The contents are as follows:

//456.php!--? phprequire_once "123.php"; echo "456\n";//test_require.php
     Run test_require.php with the following result: 

third, mixed error

If you use the Require method in 456.php, the Require_ Once method, then the require_once will fail. Three file codes are as follows:

//123.php!--? Phpecho "123\n";//456.php
       The result of the operation is as follows:  


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

Copyright notice: This article is a blogger original article, not allowed to be reproduced without the permission of Bo master.

Above introduces the use of PHP require_once and the differences with require, Include aspects of the content, you want to be interested in PHP tutorial friends helpful.

  • 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.