私のスクリプトでは、インクルード パスを設定し (アプリケーションの別の部分にもファイルをインクルードできるように)、ファイルが存在することを確認してインクルードします。
ただし、インクルード パスを設定した後file_exists()
、ファイルが存在しないと報告されますが、それでも同じファイルを含めることができます。
<?php
$include_path = realpath('path/to/some/directory');
if(!is_string($include_path) || !is_dir($include_path))
{
return false;
}
set_include_path(
implode(PATH_SEPARATOR, array(
$include_path,
get_include_path()
))
);
// Bootstrap file is located at: "path/to/some/directory/bootstrap.php".
$bootstrap = 'bootstrap.php';
// Returns "bool(true)".
var_dump(file_exists($include_path . '/' . $bootstrap));
// Returns "bool(false)".
var_dump(file_exists($bootstrap));
// This led me to believe that the include path was not being set properly.
// But it is. The next thing is what puzzles me.
require_once $bootstrap;
// Not only are there no errors, but the file is included successfully!
絶対ファイルパスを指定せずにインクルード パスとインクルード ファイルを編集できますが、それらが存在するかどうかを確認できません。存在しないファイルが呼び出されるたびに、私のアプリケーションは致命的なエラー、またはせいぜい警告 (を使用include_once()
) になるため、これは本当に面倒です。
残念ながら、エラーと警告をオフにすることはできません。
誰でもこの動作の原因を説明できますか?