Jump to content

How to write errorHandler to catch any kind of error?


eki33

Recommended Posts

Hi,

 

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
set_error_handler("handleError");
session_start();

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 ?

 

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.

 

http://php.net/manual/en/function.set-error-handler.php

 

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().

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.