Simple site hosted on shared server running Apache and PHP5. Minimal use of php at this time but do use a number of scripts for maintenance and improved functionality.
Virtual root ./htdocs/ PHP include files located in ./htdocs/lib/php/
HTML files and PHP files (other than files stored in ./htdocs/lib/php/) located in
.htdocs/(DomainName)_htdocs/

Currently calling includes using following

include $_SERVER['DOCUMENT_ROOT'] . "/lib/php/foo.php";
include $_SERVER['DOCUMENT_ROOT'] . "/lib/php/foo2.php";
include $_SERVER['DOCUMENT_ROOT'] . "/lib/php/foo3.php"; 

Works fine from any directory level without having to to remember how many levels I am down from ./
(Was that ../../../ or ../../../../ ?) One oops less and saves some time without seeming to impact performance

Most scripts need several includes (or sometimes require) eg: connection files, function files, etc. Question is can you (easily) include several files in one include call? As run to the library and fetch all this sh*t in one trip?

Have spent several days lookin' and readin' without finding a solution. Probably means there isn't one that is less trouble than include \n include \n include.....

Not really a big thing just seems like it would be a bit more elegant. 400 lines, what's 3 more?

Appreciate any suggestions or comments
TIA

    Put all the includes into one file and include that?

      No built-in way I know of. But if we're talking class definitions, you can define an __autoload() function to, well, automatically load them -- as long as there is some sort of naming convention that you can depend upon to derive the pathname from the class name. I suppose for other includes you could define a function that takes an array of strings, which you could then loop through to include() them...though you'd have to include the file with that function definition first. 🙂

        Or I suppose you could do something like this, though I don't think it really gains you anything (except a bit of extra processing?):

        foreach(array('path/one.php', 'path/two.php', 'path/three.php') as $path) { include $path; }
        

        Frankly, if I had to maintain that code, I'd prefer it was simply 3 separate calls to include().

          Thanks for the input everyone. Guess I will just keep it simple.

          Tks Again

            Write a Reply...