一、错误的级别
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
=’地址’:错误日志保存的地址
在项目开发过程中有两个模式,开发模式,运行模式
开发模式:错误显示在浏览器上,不要记录在日志中
运行模式:错误不显示在浏览器上,记录是日志中
<?php $debug=false; //true:开发模式 false:运行模式 ini_set('error_reporting',E_ALL); //所有的错误有报告 if($debug){ ini_set('display_errors','on'); //错误显示是浏览器上 ini_set('log_errors','off'); //错误不显示在日志中 }else{ ini_set('display_errors','off'); ini_set('log_errors','on'); ini_set('error_log','./err.log'); //错误日志保存的地址 } //测试 echo $num;
四、自定义错误
通过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 '记录在日志中,上班后在处理<br>'; break; case E_WARNING: case E_USER_WARNING: echo '给管理员发邮件<br>'; break; case E_ERROR: case E_USER_ERROR: echo '给管理员打电话<br>'; break; } echo "错误信息:{$errstr}<br>"; echo "错误文件:{$errfile}<br>"; echo "错误行号:{$errline}<br>"; } 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
