問題を再現する手順:
合計3つのファイルがあります
include.php には以下が含まれます。
<?php
$var1 = 5 + $var1;
?>
require.php には以下が含まれます:
<?php
$var2 = 5 + $var2;
?>
incvsreq.php には以下が含まれます。
<?php
$var1 = 0; // Starting with 0
include('include.php'); // Includes the file so Adding 5 + 0
echo $var1.'<br/>'; // Result 5
include_once('include.php'); // Will not include as it is already included
echo $var1.'<br/>'; // Display again 5, as it was not included above
include('include.php'); // This will include again so 5 + 5
echo $var1; // Result 10
rename('include.php', '_include.php'); // Rename the file
include('include.php'); // Warning should occur on this line as the file is not present now, but the script should continue.
$var2 = 0; // Starting with 0
require('require.php'); // Includes the file so Adding 5 + 0
echo $var2.'<br/>'; // Result 5
require_once('require.php'); // Will not include as it is already included
echo $var2.'<br/>'; // Display again 5, as it was not included above
require('require.php'); // This will include again so 5 + 5
echo $var2; // Result 10
rename('require.php', '_require.php'); // Rename the file
require('require.php'); // ERROR should occur on this line as the file is not present now, and the script should not continue.
echo 'This is not displayed'; // This won't be displayed.
?>
このスクリプトの出力は次のとおりです。
5
5
10
Warning: include(include.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 23
Warning: include(include.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 23
Warning: include() [function.include]: Failed opening 'include.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files\Ampps\www\include\incvsreq.php on line 23
5
5
10
Warning: require(require.php) [function.require]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 45
Warning: require(require.php) [function.require]: failed to open stream: No such file or directory in C:\Program Files\Ampps\www\include\incvsreq.php on line 45
Fatal error: require() [function.require]: Failed opening required 'require.php' (include_path='.;C:\php\pear') in C:\Program Files\Ampps\www\include\incvsreq.php on line 45
致命的なエラーは最後と上から 3 番目の警告でわかりましたが、他の警告はどのように表示されましたか? 私はここで少し混乱しています。理解を深めるために、各行にコメントを付けました。