At the top of init.php, you could use debug_backtrace()
to get information about the stack. This will tell you, among other things, which file included the current file, and at what line.
This is a sample of the backtrace output. If you put this in a function, you'll have another layer of data. If you call it right in the file itself, then the top-most layer tells you what file included that one.
array (size=2)
0 =>
array (size=3)
'file' => string 'fileThatIncudedMe.php' (length=63)
'line' => int 6
'function' => string 'require_once' (length=12)
You could wrap this up into a utility function:
function whoIncludedThisFile() {
$bt = debug_backtrace();
$includedMe = false;
while (count($bt) > 0) {
$set = array_shift($bt);
if (
array_key_exists('function', $set) === true &&
in_array($set['function'], array('require', 'require_once', 'include', 'include_once'))
){
$includedMe = array('file'=>$set['file'], 'line'=>$set['line']);
break;
}
}
return $includedMe;
}
print_r(whoIncludedThisFile());
// Array ( [file] => topLevelFile.php [line] => 2 )