Search code examples
phpinclude-pathini-setset-include-path

Include path ignored


I have the following code (simplified) to add a path to my include paths (to temporarily fix an website with old code).

set_include_path(get_include_path() . PATH_SEPARATOR . '/foo/bar');

I have a settings file /foo/settings/settings.inc.php

Now when I have set the include path and I am in a file /foo/bar/members.php I want to include the settings file. So what the code does is:

include '../settings/settings.inc.php'

I would think that it would get that file now. But it doesn't. When I put the full path in the include it does work. eg: /foo/settings/settings.inc.php but there are a lot of files. And I thought that this would be a work around for that so I don't have to replace every file manually.


Solution

  • I'd say you can't do that:

    Files are included based on the file path given or, if none is given, the include_path specified. [...]

    If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether.