PHP包含路径:我做错了什么?

OK I'm quite sure this is the easiest question someone out there will ever answer.

I try to get and echo the contents of a file in the same level:

die(file_get_contents('test.txt')); //"hello"

Works fine. I try to invalidate that call by setting a bad include path:

set_include_path('non-existant-dir');
die(file_get_contents('test.txt')); //still "hello"

...but it still finds the file. Shouldn't set_include_path mean the call to file_get_contents looks for test.txt in a dir called non-existant-dir, and thus fail?

In your php.ini config look for include_path which overrides the set_include_path function and commment it out then restart apache.

The function "file_get_contents" can take several arguments - one of which is a combination of flags where one such flag is "FILE_USE_INCLUDE_PATH" - by default I don't think it will use the include path so it makes no difference what you set the include path to. Try:

set_include_path('non-existant-dir');
die( file_get_contents('test.txt', FILE_USE_INCLUDE_PATH) );