Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 932
  • Last Modified:

Using Custom PHP Error Handler, but Parse and Fatal errors are not passed through the handler

Hi.

I'm running a custom PHP error handler on my site which so far detects all errors, except for parse and fatal errors.

I've accidently added a '>' to a PHP file after the '<?' which has generated a parse error.

What do I need to do to force all parse and fatal errors through the error handler?

Any example code would be greatly appreciated. Thanks in advance.
<?php
	ob_start();
	function ErrorHandler($errno, $errstr, $errfile, $errline) {
		ob_clean();
		include("errors/errorhandler.php"); exit();
		ob_get_clean();
	}
	set_error_handler("ErrorHandler", E_ALL^E_NOTICE);
?>

Open in new window

0
DReade83
Asked:
DReade83
  • 2
2 Solutions
 
steelseth12Commented:
error_reporting(0);
0
 
DReade83Author Commented:
That doesn't work - all it does is gives me a white screen. The custom error handler still doesn't run.

Could you be a little more specific where that line needs to go please?
0
 
steelseth12Commented:
after doing some testing you have to set it in the php.ini to disable error reporting on parse & fatal errors.

error_reporting  = ~E_ALL

And even then according to php.net although errors are not longer display you can not catch them

http://www.php.net/manual/en/function.set-error-handler.php
0
 
itsbthCommented:
It is impossible to catch fatal and parse errors, as fatal, as the suggests, is impossible to recover from and parse errors are happens before any of the code actually runs, so the handler is never registered.

From the PHP manual (http://php.net/manual/en/function.set-error-handler.php):  "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.

If errors occur before the script is executed (e.g. on file uploads) the custom error handler cannot be called since it is not registered at that time."
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now