2009-08-20 92 views
4

我有一个由许多PHP文件组成的大型复杂PHP项目。PHP:列表全部包含

是否有一些函数可以在我的代码中调用,它将返回所有包含文件的列表?

回答

14

get_included_filesget_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 
+0

非常好,不知何故,我无法在文档中找到它。 – Liam 2009-08-21 08:46:56

+0

您可以使用'var_dump(get_included_files())'而不是使用foreach循环。该函数返回一个数组。 – 2017-03-06 17:47:20

1
register_shutdown_function(
    function() { 
     your_logger(get_included_files()); 
    } 
); 

get_included_files将被称为在脚本执行结束,所以你会得到包含文件的完整列表

+0

虽然这可能是答案,但建议在答案中包含文档和/或解释。 – Pietu1998 2015-01-26 10:31:59