我第一次尝试设置错误处理。
如果有错误,它确实可以工作并报告错误,但由于某种原因,它总是显示错误处理函数本身的“缺少参数”错误。请注意我的错误处理函数在一个单独的文件中,并且包含在索引页面中,我不确定这是否是问题:S
这是我的错误处理功能
function errorHandler($errno, $errstr, $error_file, $error_line) {
if(isset($errstr)) {
# There is an error, display it
echo $errno." - ".$errstr." in ".$error_file." at line ".$error_line."<br>";
} else {
# There isn't any error, do nothing
return false;
}
}
// We must tell PHP to use the above error handler.
set_error_handler("errorHanlder");
这是索引页面
<!-- # Error Handler -->
<? if(errorHandler()) { ?>
<section id="error-handler">
<?=errorHandler();?>
</section>
<? } ?>
这是浏览器中的结果(请记住,没有 php 错误,所以这个错误处理程序不应该输出任何东西 - 这是我无法理解的
2 - Missing argument 1 for errorHandler(), called in index.php on line 20 and defined in inc/arcError.fnc.php at line 10
2 - Missing argument 2 for errorHandler(), called in index.php on line 20 and defined in inc/arcError.fnc.php at line 10
2 - Missing argument 3 for errorHandler(), called in index.php on line 20 and defined in inc/arcError.fnc.php at line 10
2 - Missing argument 4 for errorHandler(), called in index.php on line 20 and defined in inc/arcError.fnc.php at line 10
知道为什么 PHP 会报告缺少的参数吗?