PHP在运行时, 针对严重程度不同的错误,会给以不同的提示,这里简单介绍下, 方便需要的朋友
PHP在运行时, 针对严重程度不同的错误,会给以不同的提示。
eg:在$a没声明时,直接相加,值为NULL,相加时当成0来算.但是,却提示NOTICE,即注意.
我们在开发中, 为了程序的规范性,把报错级别,调的比较高NOTICE级别的也报出来,有助于我们快速定位错误和代码规范,香港服务器,网站空间,但是,在产品上线后,网站运营过程中,就不宜报这么多错.
1:这种错误给客户的印象不好
2:在报错时,把网站的绝对路径,如D:\www\1015都报出来了.增大被攻击的风险
因此,在网站上线后,就应该让报错级降低,少报错甚至不报.
修改报错级别:
1: php.ini里修改error_reporting 选项
2: 可以在php页面里,用error_reporting()函数来修改
错误级别用2进制的值来表示的: 1111 1111 1111 111从左到右,每位上的1,代表一种错误级别
fatal error致命错误: 0000 0000 0000 001 开启 1
warning 警告错误 : 0000 0000 0000 010 开启 2
NOTICE 警告 : 0000 0000 0001 000 开启 8
eg:
都报出来: error_reporting(11);
不要报NOTICE: error_reporting(3);
任何错误都不报: error_reporting(0);
系统为我们把各个级别的值,用系统常量代替了.
E_ERROR 1
E_WARNING 2
E_NOTICE 8
报所有错误: error_reporting(E_ALL);
除了NOTICE,其他都报: error_reporting(E_ALL & ~E_NOTICE);
在开发中,报错级别高一点,在上线产品中,报错级别要低:+
复制代码 代码如下:
define('DEBUG',true); // 在开发时,声明一个DEBUG模式
if(defined('DEBUG')) { //检测到处于开发模式
error_reporting(E_ALL);
} else {
error_reporting(0);
}

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
