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

发表日期:2021-07-01 08:55:06 | 来源: | | 浏览(838) 分类:PHP 选项/信息 函数

get_included_files

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

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

说明

get_included_files(): array

返回所有被 includeinclude_oncerequirerequire_once 的文件名。

返回值

返回所有文件名称的 array。

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

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

范例

示例 #1 get_included_files() 范例

<?php 
// 本文件是 abc.phpinclude '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

注释

注意:

使用 auto_prepend_file 配置指令所包含的文件不会包含在返回的数组里。

参见

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

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。