开发者

PHP set_include_path

I have a MainClass.php file with other .php files in the same directory. I noticed that I can include other .php file开发者_C百科s inside this file by using:

require "file.php";

and it seems to load them even if I don't specify the full path to the script. Will this work on any server setup? Or do I have to manually add the full path or change the include path:

set_include_path(dirname(__FILE__));

before the require statements

?


By default, PHP's include path includes .. This represents the current working directory (CWD) which is why your includes are working.

I think it best to play it safe and use an explicit include path or absolute paths wherever possible as indicated in your question.

A popular method is

set_include_path(implode(PATH_SEPARATOR, array(
    $applicationIncludePath,
    get_include_path()
));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜