Jump to content

How to write errorHandler to catch any kind of error?


Recommended Posts



I'm confused with PHP errorhandling.

I wrote this in order to record erros into a session array variable (an display it later to debug...) :


error_reporting(-1); // reporte tous les types d'erreurs

function handleError($errno, $errstr,$error_file,$error_line) {
if (!isset($_SESSION['errorLogCounter'])) $_SESSION['errorLogCounter'] = 1; 
else $_SESSION['errorLogCounter']++;
$errorDate = date("Y-m-d H:i:s (T)");
$newstring = "<b>Error Number $_SESSION[errorLogCounter]</b><br/>Date : $errorDate<br/> Error type : $errno <br/> Description : $errstr <br/> Fichier : $error_file <br/> ligne : $error_line <br/> --------------- <br/><br/>";
$_SESSION['errorlog'][$_SESSION['errorLogCounter']] = $newstring;


but it only record error and no NOTICE (owever notices are well recorder in php_error.log), why ?


Link to comment
Share on other sites

i think for the reason that they are notices and not errors


The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.




Link to comment
Share on other sites

You would need to post your test code for the first two cases.


Using a custom error handler won't work at all for parse errors in your main file because your main code never runs to call the set_error_handler() when there is a parse error in your main file. It should work for parse errors in included/required files, after the point where you call set_error_handler().

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.