How to catch all php error

I need a solution to catch all the fatal php errors, exceptions, warnings, etc .... and give a callback. Therefore, I can display a friendly version for the user and log this error. About the logging method. My php script allows many sites to work with one installation. I think I will use a text file for every day. Any sugesstion or php class, lib?

+4
source share
4 answers

This causes all errors to become exciting instances of ErrorException :

 set_error_handler(function($errno, $errstr, $errfile, $errline ){ throw new ErrorException($errstr, $errno, 0, $errfile, $errline); }); 

use it before code that may give errors for instances in the very top corner of your php file or in the general header included

+5
source

I really like error handling from the kohana system. You have to do a bit of work to get it out though.

http://kohanaframework.org/

This will allow you to register errors in the file and send it to the recipient by e-mail. It also allows you to redirect your friendly page with an error.

0
source

Try to run this web page, you will see "Message: Division by zero."

 // Set Error Handler set_error_handler ( function($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, $errno, 0, $errfile, $errline); } ); // Trigger an exception in a try block try { $a = 3/0; echo $a; } catch(Exception $e) { echo 'Message: ' .$e->getMessage(); } 
0
source

Source: https://habr.com/ru/post/1333110/


All Articles