重新生成问题的步骤:
共有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
我从顶部听到了上一次和第三次警告中的致命错误但是其他警告是如何出现的?我在这里有点困惑。为了更好地理解,我对每一行进行了评论。
答案 0 :(得分:0)
understood the Fatal Error in the last and 3rd warning from the top but how did other warnings appear ? I am little confused here.
如果您详细查看错误日志。正如您所期望的那样,只在两行上生成错误消息。第23行和第45行。即使它们显示3次,它们也仅在您要求的那两行上生成。此代码似乎表现得应该
答案 1 :(得分:0)
错误行在几个不同级别的报告和生成MSG 打印出来的内容由PHP中设置的error_reporting级别控制 有关更多信息,请查看PHP文档... error_reporting