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 ():
- When include introduces a file, if it encounters an error, it will give a hint (Warning) and continue running the code below.
- Read and evaluate each time the file is executed
- is usually placed in the processing section of the Process Control
- The php script file reads the include () statement to read the file it contains.
- Include () is a conditional include function
Require ():
- Require introduces a file, if it encounters an error, it will give a hint (Fatal error) and stop running the code below.
- The file is processed only once (in fact, the file contents replace the Require () statement)
- Usually placed at the front of the PHP script
- Before the PHP program executes, it will read into the file introduced by the Require () statement, making it part of the php script file.
- 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.