我有一个由许多 PHP 文件组成的大型复杂 PHP 项目。
我可以在代码中调用一些函数来返回所有包含文件的列表吗?
get_included_files
或 get_required_files
(get_included_files
的别名)
http://us.php.net/manual/en/function.get-included-files.php
http://us.php.net/manual/en/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 将在脚本执行结束时被调用,因此您将获得包含文件的完整列表
我继承的应用程序有数百个 PHP 文件,其中大多数包含条件逻辑 if/switch 语句,块内包含 include/require 语句。我想知道是否有免费或付费实用程序可以查看顶级文件并扫描 include/require/include_once/require_once 语句并递归遍历文件以获取可能包含的所有文件的完整列表。节点树或类似的视图将是理想的选择,尽管直接列表会有所帮助。我试图找到从未被调用的文件,因为最后一个开发人员习惯使用与我所知道正在执行的文件类似但有些融合的名称进行多个备份。感谢您提供的任何建议。