In-depth understanding of include/require in PHP
include
1. First search for the file according to the path of the loaded file. If it is just a file name, it will be searched according to the include_path
2. If the above two addresses are not found, the directory where the script file is located and the current working directory will be called
3. If it is not found at the end, a warning will be issued. This is different from require, which will issue a fatal error
4. If path is defined. Regardless of absolute path or relative path, include_path will be invalid
require
1. Same as include method, but different error handling methods
2. When the require file is not loaded, the script will stop executing.
include_path in php
php when encountering include or require
1. First determine whether it is the right path.
Yes->Load and end
No ->Enter another logic (after multiple calls, macro expansion into _php_stream_fopen_with_path) to find this file)
<code>更详细案例说明参阅鸟哥文章: </code>
http://www.laruence.com/2010/05/04/1450.html
Conclusion It is best to use absolute paths
The difference between include and require
include(): When
require():
<code><span><span><?php</span><span>//变量$ok无论是何值,1.php都会被包含进来[在PHP程序执行前,就读入require()语句]</span><span>if</span>(<span>$ok</span>){ <span>require</span><span>'1.php'</span>; } <span>//变量$ok为真,则包含文件2.php</span><span>if</span>(<span>$ok</span>){ <span>include</span><span>'2.php'</span>; } <span>?></span></span></code>
Conclusion
The above has introduced an in-depth understanding of include/require in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.