関数 get_included_files

関数 get_included_files は、現在のスクリプトに接続されたすべてのファイルの絶対パスの配列を返します。 これは、どのファイルが実際に読み込まれたかを確認する必要があるデバッグ時に便利です。

構文

phpget_included_files();

例

簡単なスクリプトでインクルードされたファイルの一覧を確認しましょう:

php<?php
  include 'header.php';
  require 'config.php';
  
  $res = get_included_files();
  print_r($res);
?>

コードの実行結果:

php[
  '/path/to/main.php',
  '/path/to/header.php',
  '/path/to/config.php'
]

例

インクルードされたファイルの数を確認しましょう:

php<?php
  include 'functions.php';
  include_once 'utils.php';
  
  $res = count(get_included_files());
  echo $res;
?>

コードの実行結果:

php3

関連項目