Skip to content

Instantly share code, notes, and snippets.

@Xatenev
Created May 13, 2015 14:46
Show Gist options
  • Save Xatenev/43418a7e30969d324fd5 to your computer and use it in GitHub Desktop.
Save Xatenev/43418a7e30969d324fd5 to your computer and use it in GitHub Desktop.
WhoIncludedThisFile
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 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment