2009-08-20 43 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