Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6704409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:07+00:00 2026-05-26T07:17:07+00:00

I am in the middle of refining a rather large bit of code. Alot

  • 0

I am in the middle of refining a rather large bit of code. Alot of it contains many general warnings and notices which do not affect the execution of the code (ie: undefined varilables, or array keys without qoutes).

I want to write a function which allows me to concentrate on the fatal errors first and then I will open it up to the less urgent warnings and notices. I found this code, but it emails every little warning notice and error.

http://net.tutsplus.com/tutorials/php/quick-tip-email-error-logs-to-yourself-with-php/

How can I modify this code so it only deals with things like:

  • fatal syntax errors
  • undefined functions
  • failure to include files
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:17:08+00:00Added an answer on May 26, 2026 at 7:17 am

    set_error_handler allows you to specify a user-defined error handling function for deciding what to do with certain (but only non-fatal) errors. You can then handle specific types of errors in any fashion you deem necessary, for example notifying a system administrator via email, or saving to a specific log file. See: PHP Doc for further details.

    With regards to your request you could the following approach:

    function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
      if (!(error_reporting() & $errno)) {
        // This error code is not included in error_reporting
        return;
      }
    
      switch ($errno) {
        case E_USER_ERROR:
        case E_ERROR:
        case E_COMPILE_ERROR:
          echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
          echo "  Fatal error on line $errline in file $errfile";
          echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
          echo "Aborting...<br />\n";
          emailErrorFunction($errno,$erstr,$errfile,$errline);
          exit(1);
          break;
    
      default:
          echo "Unknown error type: [$errno] $errstr<br />\n";
          break;
      }
    
    /* Don't execute PHP internal error handler */
      return true;
    }
    // Report all errors
    error_reporting(E_ALL);
    // User a custom error handler to print output
    set_error_handler( 'myErrorHandler' );
    

    As that error-handling does not work for Fatal Errors (Parse errors, undefined functions etc.), you need to tape this with register_shutdown_function as outlined in a related question:

    • How do I catch a PHP Fatal Error
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the middle of overhauling some code and I hit a bit of
I'm in the middle of writing some code to possibly extend some modules in
I'm in the middle of a significant effort to introduce NHibernate into our code
In the middle of a c++ code, eclipse, I need to compute the multiply
I am in the middle of solving a problem which requires me to do
I am in the middle of developing a PHP social media web application which
I'm in the middle of refactoring some code on my current project, and I'd
how to find the middle of the linked list when we are not informed
I'm in the middle of porting some c++ code to java, and I keep
I am in the middle of developing a Django application, which has quite complicated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.