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
include(dirname(__FILE__).'/Config.inc');
- this will always work, regardless of theinclude_path
and which file "Common.php" is included into. If there is no chance "Config.inc" could be found in theinclude_path
(in which the current directory is often included) then you could simply callinclude 'Config.inc';
, although this is possibly less efficient since theinclude_path
is first searched (which fails). – Psychochemicalinclude('sub\2.php');
would never work.) – Psychochemical