php - 使用@时跳过报告错误(错误控制运算符)

标签 php error-handling

我的代码是:

function errors($number,$string,$file,$line)
{
    $error = $string.' In '.$file.', on line '.$line."\n";
    error_log($error);
}
set_error_handler('errors',E_ALL);

下一行停止显示错误,因为我正在使用@运算符。但是,我的问题是set_error_handlererror.log文件中写入了错误。
echo @$undefined_variable; // I don't want to write this error in error.log file

最佳答案

尽管更好的解决方案是解决 undefined variable 问题,但是您可以按照以下要求进行操作:

ini_set('log_errors', false);
echo $undefined_variable;
ini_set('log_errors', true);

同样,我强烈敦促您解决问题(定义变量或在使用变量之前使用isset进行检查),而不要掩盖错误。

关于php - 使用@时跳过报告错误(错误控制运算符),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22548707/

相关文章:

php - MySQL:LEFT JOIN 或 UNION 表并将列值设置为列名?

Android IAB 错误 RPC :S-7 AEC-0

excel - 在 Excel 中调试 VBA 类中的错误

internet-explorer - 网络浏览器: is there an equivalent to a compiler “warnings as errors” switch?

php - 处理来自Symfony应用程序的MySQL错误

c# - 使用EventLog类在Windows 2003 Server上记录错误

php - Laravel 框架错误 : SQLSTATE[42000]: Syntax error or access violation: 1064

php - 将选择表单的值插入mysql

javascript - 如何从数据库向本地计算机发出实时通知

php - 如何在xampp上安装mysql到php5?