we use this bit to include the lib called dir_lib.php
that lib has one f in it, called trans_path
so even if we have to unclude a second lib in the same page, we already do
include trans_path("lib2.php");
which does the same thing as above many lines of code to the next lib.
it also takes care of preventing recursive includes, such as:
a.php: include b.php
c.php: include a.php; include b.php;
as you can see, c.php would generate an error as a already includes b, so when parsing c will get to point of including b, it will generate a number of errors saying functions (vars, etc) are already declared.
to prevent this, each lib is started like this:
lib1.php:
$lib1_included = true;
other lib1 stuff
So the actual include lines are:
if(!$lib1_included) include trans_path("lib1.php");
furthermore, we found ourselves in a situation where we had to mix pages written in different languages inside one application (migration / rewrite / integration with very little time).
so we created a trans_path function in each of the languages, and started simply doing trans_path("lib1"); so that the PHP version adds .php to the end of the lib, and ASP version .asp, etc.
Then we even took it another step further, and made the function check whether the lib is already included:
now we simply do include trans_path("lib1"); without the IF checking.
the function does the checking
function trans_path($lib)
{
$libIncludedVarName = $lib . "_included";
if($$libIncludedVarName)
$libPath = "emptyfile.php"
else
$libPath = $realPath . $lib . ".php"; // real path calculated right before this line
return $libPath;
}
in above, emptyfile.php is in fact simply an empty file, and can therefore be included any number of times without generating the "already declared" error.