大网数据广告活动
PHP 语言与运行手册

get_included_files · 返回被 include 和 require 文件名的 array

· 52CE 我爱测

get_included_files — 返回被 include 和 require 文件名的 array

get_included_files

(PHP 4, PHP 5, PHP 7, PHP 8)

get_included_files — 返回被 include 和 require 文件名的 array

说明

function get_included_files(): array

返回所有被 include、 include_once、 require 和 require_once 的文件名。

参数

此函数没有参数。

返回值

返回所有文件名称的 array。

脚本最初被称为”被包含的文件“,所以脚本自身也会和 include 系列函数引用的脚本列在一起。

被多次 include 和 require 的文件在返回的 array 里只会列出一次。

示例

示例 #1 get_included_files() 示例

<?php
// 本文件是 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";
}

?>

以上示例会输出:

/path/to/abc.php
/path/to/test1.php
/path/to/test2.php
/path/to/test3.php
/path/to/test4.php

参见

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。