It's very odd,has anyone ever sum up with a conclusion yet?
Sometimes it checks the directory of the included file,too.
But sometimes not.
D:\test\1.php
<?php
include('sub\2.php');
D:\test\2.php
<?php
include('3.php');
Where 3.php
is in the same dir as 2.php
.
The above works,but why?The current directory should be D:\test
,but it can still find 3.php,which is in D:\test\sub
More story(final)
About a year ago I met this problem,and then I ended up fixed it with the hardcoding like below:
Common.php:
if (file_exists("../../../Common/PHP/Config.inc"))
include('../../../Common/PHP/Config.inc');
if (file_exists("../../Common/PHP/Config.inc"))
include('../../Common/PHP/Config.inc');
if (file_exists("../Common/PHP/Config.inc"))
include('../Common/PHP/Config.inc');
if (file_exists("Common/PHP/Config.inc"))
include('Common/PHP/Config.inc');
Where Config.inc
is in the same directory as Common.php
Sometimes directory of the included file being
current working directory
and sometimes notCurrent directory can be checked with
getcwd()
If you take a look at the source code for php in main/fopen_wrappers.c you will find
This seems to be executed unconditionally and therefore will always make a file in the same path as the including/file-opening script accessible ...as the last choice after all possibilities specified in include_path. And only if you do not define a relative or absolute path in the include().
It checks in the current path, and the directories listed in include_path.
You can run a
phpinfo()
to see your include path.