0

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.

Matthijn
  • 3,126
  • 9
  • 46
  • 69

1 Answers1

0

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.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • So as soon as there is something of a path (e.g `../file.php` or `/foo/file.php` it completely ignores the include path? And it only uses the include path if I give `file.php` only? Hmm. Well, than all I can do is change a lot of files. – Matthijn May 07 '14 at 15:24
  • I have no idea of what you're trying to accomplish but... Why is batch search and replace unfeasible? It's a two minute task with any decent editor? – Álvaro González May 07 '14 at 15:30
  • And that is the route I went. – Matthijn May 07 '14 at 15:37
  • Whatever you're doing... I've heavily used the [auto_prepend_file](http://php.net/auto_prepend_file) directive to make really ugly and old sites work in modern servers. Good luck :) – Álvaro González May 07 '14 at 15:43