search
Homephp教程php手册PHP错误处理

PHP错误处理

Jun 13, 2016 am 08:50 AM
phpClassificationonlydeal withhintofprogramgrammarrunRuntimemistake

PHP错误处理

PHP错误处理

 

错误的分类:

 

    语法错误:程序没法运行,直接提示语法错误

    运行时错误:只有程序运行到某行,或在某此特定的情形下运行才会发生的错误。

    逻辑错误:程序从头到尾运行都没有发生(并提示)错误,但程序运行计算的结果是错误的。

 

程序员主要面对的和要处理的错误,就是运行时错误。

 

错误的分级:

    

    在php中,将各种错误,分门别类,依据不同的严重程序和产生的来源(机制),将各种错误分为大约十几个级别。

    每个级别的错误,都对应一个内部的名称--系统常量!

 

系统错误:

 

    E_ERROR 系统严重错误 (一发生,程序立即停止执行。该错误一般希望马上解决)

    E_WARNING 系统警告   (一发生,提示错误,并继续执行。通常该错误希望能够在“下一工作日”去处理掉)

    E_PARSE 语法错误    (一发生,提示错误,而且代码完全不会运行--在运行之前先检查语法。)

    E_NOTICE 系统提示    (一发生,提示错误,并继续执行。发个邮件通知下,自己安排时间有空去解决。)

 

    它们的本质是什么呢?

 

echo "
E_ERROR =  ".E_ERROR;

echo "
E_WARNING =  ".E_WARNING;

echo "
E_PARSE =  ".E_PARSE;

echo "
E_NOTICE =  ".E_NOTICE;

 

输出的结果分别为:

 

E_ERROR = 1

E_WARNING = 2

E_PARSE = 4

E_NOTICE = 8

 

可见它们只是一个系统内部的常量(整数常量);实际上,这些常量(代号)是供我们对该类错误进行“控制”的标示符而已。

 

用户自定义错误:

    只有三个:

    E_USER_ERROR

    E_USER_WARNING

    E_USER_NOTICE

我们可以在程序中,自己创建(生成)错误 -- 是为了针对某些数据的不合理情形而创建的错误

    比如:让用户填写年龄,填18是OK,但填写188,则就是不合理 -- 从数字角度本身是没有问题的

 

其它错误:

    E_ALL       代表所有错误 -- 表示它可以“包括”所有错误。

    E_STRICT    代表“严格性”语法检查错误 -- 某种语法是可以执行的,但在当前的php版本是不欢迎使用。

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function