eki33 Posted September 17, 2012 Share Posted September 17, 2012 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/268470-how-to-write-errorhandler-to-catch-any-kind-of-error/ Share on other sites More sharing options...
spiderwell Posted September 17, 2012 Share Posted September 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/268470-how-to-write-errorhandler-to-catch-any-kind-of-error/#findComment-1378639 Share on other sites More sharing options...
PFMaBiSmAd Posted September 17, 2012 Share Posted September 17, 2012 Your code works for warnings and notices. What makes you think it does not? Quote Link to comment https://forums.phpfreaks.com/topic/268470-how-to-write-errorhandler-to-catch-any-kind-of-error/#findComment-1378643 Share on other sites More sharing options...
eki33 Posted September 17, 2012 Author Share Posted September 17, 2012 Thanks for your replies, Not catched by my function : PHP Warning: Division by zero... PHP Notice: Undefined index... PHP Parse error: syntax error, unexpected... Quote Link to comment https://forums.phpfreaks.com/topic/268470-how-to-write-errorhandler-to-catch-any-kind-of-error/#findComment-1378688 Share on other sites More sharing options...
PFMaBiSmAd Posted September 17, 2012 Share Posted September 17, 2012 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(). Quote Link to comment https://forums.phpfreaks.com/topic/268470-how-to-write-errorhandler-to-catch-any-kind-of-error/#findComment-1378704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.