tags:

views:

193

answers:

3

Where would

set_include_path("../../");

point to?

I am trying to run some PHP code on a standard XAMPP server. And put my stuff into the htdocs folder. The includes point to relative paths, But it does not work. Is there any best-practise for includes? The code has to run on machines of multiple developers.

+1  A: 

Two directories down from where the file (or the file which included it) is running from.

As for best practices there are only two advices i can give you.

  1. Use relative paths.
  2. If relative paths are giving you trouble, use an absolute path as a single static variable and the developers only change that one variable.
Ólafur Waage
+1  A: 

Relative path should work fine (warning: apache on windows, as I know, don't follow the simlinks, or whatever are called on that os).

Maybe you should use the syntax (in order to avoid problem with different php versions)

ini_set('include_path', 'yourdir');

and test the return value to see if all is ok.

Turning to the best practices: To me setting an configuration directive into a script, expecially if project-wide, is wrong, or at least dangerous.

A better practice is to put the directive into the .htaccess file in the directory that contains your php files project.

Even better, it is faster, put the directives into the appropriate virtualhost section of your apache config. For develop, though, .htaccess is more flexible and therefore preferable.

It should be something like this: php_value include_path ".:../..:<your path collection>"

Doing this lets you share the php configuration w/o have fiddling with the ini_set directive in every php file you write.

Not to mention that if you have a special file that needs a custom include_path, you can set it in the file and this will be evident to everyone at a very rapid glance.

Eineki
A: 

See this related SO question about an include path strategy for more ideas.

flamingLogos