Function initialize ()
{
Set_include_path (get_include_path (). path_separator. "Core /");
Set_include_path (get_include_path (). path_separator. "app /");
Set_include_path (get_include_path (). path_separator. "admin /");
Set_include_path (get_include_path (). path_separator. "lib /");
Set_include_path (get_include_path (). path_separator. "include /");
Set_include_path (get_include_path (). path_separator. "Data /");
Set_include_path (get_include_path (). path_separator. "cache /");
}
In this way, its path becomes:
.; C: \ PhP5 \ pear; Core/; APP/; admin/; LIB/; Include/; Data/; Cache/
Ah, we found there was another one above .; c: \ PhP5 \ pear; what is going on? In fact, if we do not write anything and output the default value of include_path first, we will find that it is .; c: \ PhP5 \ pear; it allows you to introduce a file at will.
If you load many more folders, you can directly write the file name!
But just like the question I asked at the beginning, why is the code in our company different from that in other people?
Set_include_path (dirname (_ file __));
Then, when you import files from other folders, an error is reported, indicating that the files cannot be found in the folder I specified.
First, we first use another method to output:
<? PHP
Set_include_path (dirname (_ file __));
$ Include_value = ini_get ('include _ path ');
Echo $ include_value;
?>
The result is: D: \ appserv \ www.
If I find the file test4.php under WWW, no error is reported.
Include ("test4.php ");
However
Include ("test1.php ");
An error is reported:
Warning: Include () [function. Include]: Failed opening 'test1. php' for future Sion (include_path = 'd: \ appserv \ www ') inD: \ appserv \ www \ test. phpOn Line6
We also found that.; C: \ PhP5 \ pear; has been replaced. So when we use it, if we don't just introduce files in one folder, we need to add get_include_path (). path_separator.
Explanations:
Get_include_path () is the default value for obtaining the current include_path.
Path_separator is a constant, which is consistent with the include path demarcation, which is on the window; on UNIX and Linux:
Finally, let me talk about it. In fact, we can also use another method: the most primitive:
Ini_set ('include _ path', 'Directory name ');
Note the following two points:
If the file to be included cannot be found in the specified directory, and the file with this name exists in the directory of the current page, the file under the current directory is introduced by default.
When multiple directories are specified as include_path, and all files in these directories with the same name must exist, PHP selects the file in the top directory when setting include_path.
Set_include_path () & get_include_path () Usage