First, let's take a look at the description of the include file search principles in the PHP official manual:
Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E. g. If your include_path isLibraries, Current working directory is/Www/, You have DEDInclude/a. phpAnd there isInclude "B. php"In that file,B. phpIs first looked in/Www/libraries/And then in/Www/include/. If filename begins./Or../, It is looked only in the current working directory.
Find the file inclusion sequence first in the relative include_path of the current working directory, and then in the relative include_path of the directory where the current running script is located. For example, include_path is., The current working directory is/Www/, The script must includeInclude/a. phpAnd there is a sentence in this fileInclude "B. php", Then lookB. phpFirst/Www/And then/Www/include/. If the file name is./Or../First, it is only found in the include_path of the current working directory.
So the file structure is as follows:
---- A. php
---- Include/B. php
---- Include/C. php
A. php
<? PHP
Include 'include/B. php ';
?>
-----------------------
B. php
<? PHP
Include 'C. php ';
Include 'include/C. php ';
?>
--------------------------
C. php
<? PHP
Echo 'C. php ';
?>
--------------------------
Both of them can run correctly, which means that the two different inclusion paths in B. php are feasible. You can find C. php In the method of searching for inclusion files based on include.
However, the best way is to use absolute paths. If absolute paths are used, the PHP kernel will directly load files through paths without having to include paths to search for files one by one, increasing the code execution efficiency.
<? PHP
Define ('root _ path', dirname (_ file __));
Include root_path. '/C. php ';
?>
For more information about the execution performance of different file inclusion methods, see this article.