search
Homephp教程php手册PHP捕获Fatal error错误的方法_PHP教程_编程技术

这篇文章主要介绍了PHP捕获Fatal error错误的方法,使用register_shutdown_function来捕获Fatal error错误,需要的朋友可以参考下

 

Fatal error 一般是不需要捕获的, 但是在一个复杂的程序中, 如果偶然出现内存不足导致fatal error就难以处理了.

比如. fatal error 出在MySQL类中fetch的时候. 这个时候就很难定位到真正问题所在了.

PHP异常处理中 可以通过set_error_handler来捕获. 但是却只能捕获 NOTICE/WARNING级别的错误, 对于E_ERROR是无能为力的.

register_shutdown_function 能解决set_error_handler的不足.

通过此函数注册好程序结束回调函数, 就可以捕获平时捕获不到的错误了. 再通过 error_get_last 对错误进行判断. 就容易找出难以定位的问题了.

 

 

代码如下:

 

function shutdown_function()  
{  
    $e = error_get_last();    
    print_r($e);  
}
register_shutdown_function('shutdown_function');  

 



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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

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.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool