假设我有以下情况:
File1.PHP:
<?PHP require_once('init.PHP'); ... ?>
File2.PHP:
<?PHP require_once('init.PHP'); ... ?>
的init.PHP:
<?PHP magic_function_which_tells_me_which_file_parsed_this_file(); ... ?>
即使没有函数,您也可以使用debug_backtrace来查找调用者:
原文链接:https://www.f2er.com/php/134655.htmltest1.PHP
<?PHP echo 'test1'; include 'test2.PHP';
test2.PHP
<?PHP echo 'test2'; print_r(debug_backtrace());
产量
ABCArray ( [0] => Array ( [file] => /tmp/b.PHP [line] => 3 [function] => include ) [1] => Array ( [file] => /tmp/a.PHP [line] => 3 [args] => Array ( [0] => /tmp/b.PHP ) [function] => include ) )
无论如何,我不推荐使用它,因为当过度使用时它可能会有明显的性能阻力.