get_included_files()
provides a stack of the files included, in the order they are included, which in my case gave me everything I needed.
Specifically, if you call get_included_files()
within a file that has been included, that file's own file-path will be the most recent entry on the stack returned by get_included_files()
, the one that included it is above that, etc.
The caveat is that files are only listed once, so if the same file is included more than once, only the first include will show up in the stack. For my purposes that wasn't an issue, but it definitely means this won't work in all cases.
Specific example: imagine the file 'test1.php' includes 'test_include.php'. The result of get_included_files() from the perspective of 'test_include.php' after loading test1.php in the browser are as follows (given, as you can see, that I've got an auto_prepend file, which in turn loads an autoloader).
array(4) {
[0]=>
string(21) "/www/auto_prepend.php"
[1]=>
string(19) "/www/autoloader.php"
[2]=>
string(14) "/www/test1.php"
[3]=>
string(21) "/www/test_include.php"
}
So test_include.php only has to do a little array_pop'ing to figure out who included it.