PHP Include/require in-depth understanding

Source: Internet
Author: User
PHP Include/require in-depth understanding

Include
1. First press the path of the loading file to find the file, if it is only a file name, then follow include_path to find
2. If the above two addresses are not found, the script file directory and the current working directory are called
3. If not found at the end, a warning is issued. This is different from require, which makes a fatal mistake.
4. If the path is defined. No matter the absolute path and relative path, the include_path will fail

Require
1. Same as include method, but handling error method is different
2.require the file is not loaded and causes the script to stop executing.

Include_path in PHP

PHP when encountering include or require
1. First determine whether the path is according to the basis.
Yes, load and end
No, enter another logic (after multiple calls, the macro expands into _php_stream_fopen_with_path) to find this file)

Http://www.laruence.com/2010/05/04/1450.html

Conclusion it is best to use absolute path

The difference between include and require

Include ():

    1. When include introduces a file, if it encounters an error, it will give a hint (Warning) and continue running the code below.
    2. Read and evaluate each time the file is executed
    3. is usually placed in the processing section of the Process Control
    4. The php script file reads the include () statement to read the file it contains.
    5. Include () is a conditional include function

Require ():

    1. Require introduces a file, if it encounters an error, it will give a hint (Fatal error) and stop running the code below.
    2. The file is processed only once (in fact, the file contents replace the Require () statement)
    3. Usually placed at the front of the PHP script
    4. Before the PHP program executes, it will read into the file introduced by the Require () statement, making it part of the php script file.
    5. Require () is an unconditional include function

    
     //变量$ok无论是何值,1.php都会被包含进来[在PHP程序执行前,就读入require()语句]if($ok){        require'1.php';    }    //变量$ok为真,则包含文件2.phpif($ok){      include'2.php';    }?>

Conclusion

    • Incluce load when used
    • Require is loaded at the beginning
    • The _once suffix indicates that the load is not loaded
    • Using require () is more efficient if you can execute code multiple times
    • If you are reading a different file each time you execute the code, or you have a loop that iterates through a set of files, use the Include () statement

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the PHP Include/require in-depth understanding, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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