[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2007-11-19
6
Medium Priority
?
911 Views
Last Modified: 2008-10-10
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
Comment
Question by:DReade83
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 20

Expert Comment

by:steelseth12
ID: 20314182
error_reporting(0);
0
 

Author Comment

by:DReade83
ID: 20314209
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
 
LVL 20

Accepted Solution

by:
steelseth12 earned 1000 total points
ID: 20314276
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
 
LVL 1

Assisted Solution

by:itsbth
itsbth earned 1000 total points
ID: 20315399
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question