get_included_files
返回被 include 和 require 文件名的 array
PHP 4.3.0及以上版本
get_included_files 函数返回一个数组,包含当前脚本已包含的所有文件路径。此函数用于查看哪些文件已经通过 include 或 require 被加载到当前脚本中。
array get_included_files(void);
此函数不接受任何参数。
返回一个数组,数组中每个元素是一个已被包含文件的完整路径。如果没有文件被包含,则返回空数组。
以下示例演示了如何使用 get_included_files 来获取当前脚本已包含的文件列表:
// 包含一些文件 include 'file1.php'; require 'file2.php'; <p>// 获取已包含的文件<br> $included_files = get_included_files();</p> <p>// 输出包含的文件列表<br> print_r($included_files);<br>
在这个例子中,首先通过 include 和 require 包含了两个文件,分别为 'file1.php' 和 'file2.php'。然后,调用 get_included_files 函数获取包含的文件列表,并通过 print_r 输出包含文件的路径数组。
运行此代码时,输出会是类似于以下内容:
Array ( [0] => /path/to/file1.php [1] => /path/to/file2.php )