Home  >  Article  >  Backend Development  >  What are the errors in PHP? How to deal with it?

What are the errors in PHP? How to deal with it?

王林
王林forward
2019-08-29 15:00:111802browse

一、错误的级别

1.notice 提示
2.warning 警告
3.error 致命错误

notice和warning报错后继续执行,
error报错后停止执行

二、错误的提示方法

方法一:显示在浏览器上

方法二:记录在日志中

三、与错误有关的配置

在php.ini中

1. error_reporting = E_ALL:报告所有的错误
2. display_errors = On:将错误显示在浏览器上
3. log_errors = On:将错误记录在日志中
4. error_log=’地址’:错误日志保存的地址

在项目开发过程中有两个模式,开发模式,运行模式

开发模式:错误显示在浏览器上,不要记录在日志中
运行模式:错误不显示在浏览器上,记录是日志中

四、自定义错误

通过trigger_error产生一个用户级别的 error/warning/notice 信息

/**
*自定义错误处理函数
*@param $errno int 错误类别
*@param $errstr string 错误信息
*@param $errfile string 文件地址
*@param $errline int 错误行号
*/
function error($errno,$errstr,$errfile,$errline) {
    switch($errno){
        case E_NOTICE:
        case E_USER_NOTICE:
            echo '记录在日志中,上班后在处理
'; break; case E_WARNING: case E_USER_WARNING: echo '给管理员发邮件
'; break; case E_ERROR: case E_USER_ERROR: echo '给管理员打电话
'; break; } echo "错误信息:{$errstr}
"; echo "错误文件:{$errfile}
"; echo "错误行号:{$errline}
"; } set_error_handler('error'); echo $num; //运行结果 记录在日志中,上班后在处理 错误信息:Undefined variable: num 错误文件:F:\wamp\www\4-demo.php 错误行号:50

想了解更多PHP相关内容,请访问PHP中文网:PHP视频教程

The above is the detailed content of What are the errors in PHP? How to deal with it?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete
Previous article:How to set php font colorNext article:How to set php font color