Subject: Chapter 8 - Reporting Fatal Errors
Posted By: chrlynde Post Date: 10/11/2004 7:05:02 PM
I would like to implement the PHP Error Handler from Chapter 8 into my website, but have been unable to get the script to work when it encounters a fatal error.  The problem I have been experiencing, both locally and on my remote server, is that when PHP encounters a fatal error, it appears to stop all scripts.

I have researched elsewhere and have been unable to find any reference of PHP still executing a script after it has encountered a fatal error.  I have even copied the source from www.wrox.com and placed it on my site, but still receive the same problem.

Any assistance would be greatly appreciated.  Both my server and my development machine are running PHP 4.3.8.  Below is my source code, in case it helps.  Thanks.

--------------------------------------------------------------
function handler($error_type, $error_message, $error_file, $error_line)
{
  switch($error_type)
  {
   //fatal error
   case E_ERROR:
     echo 'Hello World';
     // send mail
     $subject = $error_type . ' on line ' . $error_line . ' in ' . $error_file;
     $content = "MY EMAIL CONTENT";
     from = 'Fatal Error @ BW';
     developerMail($subject,$content,$from);
     die();
     break;
     //end script

   case E_WARNING:
     // send mail
     $subject = $error_type . ' on line ' . $error_line . ' in ' . $error_file;
     $content = "MY EMAIL CONTENT";
     $from = 'Warning @ BW';
     developerMail($subject,$content,$from);
     break;
     //script will continue

   case E_NOTICE:
     //don't show notice errors
     break;
  }
}
error_reporting(0);
set_error_handler("handler");

//cause a fatal error
fatalerror();
--------------------------------------------------------------
NOTE—The script does work when it encounters a warning.  My only problem is with fatal errors.  Thanks again.



Go to topic 20533

Return to index page 747
Return to index page 746
Return to index page 745
Return to index page 744
Return to index page 743
Return to index page 742
Return to index page 741
Return to index page 740
Return to index page 739
Return to index page 738