我想更改以下PHP
错误消息,以便用户看不到此错误,并且我想显示一个用户更容易理解的错误。
例如,考虑我要编辑的此错误,
Notice: Undefined index: user_input on line 33
我想显示以下错误消息,而不是上面的默认错误消息,
Process failed
我如何在我的网站上实现?
最佳答案
这不是一个错误,而是一个通知,因此您需要做一些事情:
例:
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
try {
//Trigger exception:
$my_array = array();
echo $my_array['undefined'];//Notice will throw exception
} catch (Exception $e) {
echo 'Process failed';
}
?>
关于php - 自定义PHP错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32402560/