codecamp

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

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

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

说明

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

参见

  • include - include
  • include_once - include_once
  • require - require
  • require_once - require_once
  • get_required_files() - 别名 get_included_files


PHP8 get_include_path — 获取当前的 include_path 配置选项
PHP8 get_loaded_extensions — 返回所有编译并加载模块名的 array
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定