我有一个由许多PHP文件组成的大型复杂的项目。
是否有某个函数可以在我的代码中调用,返回所有已包含文件的列表?
get_included_files
或者 get_required_files
(get_included_files
的别名)
http://us.php.net/manual/zh/function.get-included-files.php
http://us.php.net/manual/zh/function.get-required-files.php(get_included_files
的别名)
<?php
// This file is abc.php
include 'test1.php';
include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filename\n";
}
?>
-----
The above example will output:
abc.php
test1.php
test2.php
test3.php
test4.php
register_shutdown_function(
function() {
your_logger(get_included_files());
}
);
get_included_files()函数将在脚本执行结束时被调用,因此您将获得所有已包含文件的完整列表。
var_dump(get_included_files())
而不是使用 foreach 循环。该函数返回一个数组。 - Casper Wilkes