At the top of init.php, you can use debug_backtrace() to get stack information. This will tell you, among other things, which file included the current file and on which line.
This is a sample backtrace output. If you put this in a function, you get another layer of data. If you name it correctly in the file itself, then the topmost layer will tell you which file included this file.
array (size=2) 0 => array (size=3) 'file' => string 'fileThatIncudedMe.php' (length=63) 'line' => int 6 'function' => string 'require_once' (length=12)
You can translate this 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());
Chris baker
source share