変数「cache_path」が上部に定義されているにもかかわらず、次のコードでは次のエラーが発生します。
<b>Notice</b>: Undefined variable: cache_path in <b>C:\Users\Jan Gieseler\Desktop\janBSite\Scripts\Index.php</b> on line <b>20</b><br />
コードは次のとおりです。
header('Content-type: application/x-javascript');
$cache_path = 'cache.txt';
function getScriptsInDirectory(){
$array = Array();
$scripts_in_directory = scandir('.');
foreach ($scripts_in_directory as $script_name) {
if (preg_match('/(.+)\.js/', $script_name))
{
array_push($array, $script_name);
}
}
return $array;
}
function compilingRequired(){
if (file_exists($cache_path))
{
$cache_time = filemtime($cache_path);
$files = getScriptsInDirectory();
foreach ($files as $script_name) {
if(filemtime($script_name) > $cache_time)
{
return true;
}
}
return false;
}
return true;
}
if (compilingRequired())
{
}
else
{
}
?>
これを修正するにはどうすればよいですか?
EDIT:PHPは、「メイン」スコープにある変数を関数でも使用できるようにすると考えました。私は間違っていたと思います。助けてくれてありがとう。
「グローバル」ステートメントを使用して修正しました。