PHP include/require

Source: Internet
Author: User
: This article mainly introduces php的includerequire for more information. For more information about PHP tutorials, see. PHP include/require

Include
1. First, find the file according to the path of the file to be loaded. if it is only a file name, it will be searched according to include_path.
2. if the preceding two addresses are not found, the directory where the script file is located and the current working directory will be called.
3. if not found, a warning will be issued. This is different from require. The latter will send a fatal error.
4. If the path is defined. The include_path is invalid regardless of the absolute path and relative path.

Require
1. the include method is the same, but the error handling method is different.
2. if require does not load the file, the script will be stopped.

Include_path in php

When php encounters include or require
1. first determine whether the path is a data pair.
Yes-> load and end
No-> enter another logic (after multiple calls, expand the macro and enter _ php_stream_fopen_with_path) to find this file)

For more detailed case description, refer to the Bird's article:

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

The conclusion is that it is best to use the absolute path.

Difference Between include and require

Include ():

  1. When the include file is introduced, if an error is encountered, a prompt (Warning) will be provided and the following code will continue to run.
  2. Read and evaluate files every time they are executed.
  3. It is generally placed in the process section of process control.
  4. The include () statement is read in the PHP script file.
  5. Include () is a conditional include function

Require ():

  1. When a file is introduced by require, if an error occurs, a Fatal error is prompted and the following code is stopped.
  2. The file is only processed once (in fact, the file content replaces the require () statement)
  3. Usually placed at the beginning of the PHP script program
  4. Before the PHP program is executed, it will first read the file introduced by the require () statement to make it part of the PHP script file.
  5. Require () is an unconditional include function.

  

Conclusion

  • Incluce loaded when used
  • Require load at the beginning
  • _ Once suffix indicates that the loaded files are not loaded.
  • If the code may be executed multiple times, the use of require () is more efficient.
  • If different files are read every time code is executed, or there is a loop through a set of file iterations, the include () statement is used.

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces PHP's include/require in-depth understanding, 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.