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 7985147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:28:53+00:00 2026-06-04T11:28:53+00:00

Hello everybody a probably easy question. I need a custom error handler to report

  • 0

Hello everybody a probably easy question.

I need a custom error handler to report the notice back from a getJson call, and not violate any rule about json format of response.

So I thought of collecting all notice in a session variable and then add in a json_encode of the response

In my error handler the switch does not catch any option

<?php
session_start();

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:
    $error= "<b>My ERROR</b> [$errno] $errstr<br />\n";
    $error.= "  Fatal error on line $errline in file $errfile";
    $error.= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
    $error.= "Aborting...<br />\n";
     $_SESSION['Errors']['Errors'][]=$error;
//exit(1);
    break;

case E_USER_WARNING:
    $_SESSION['Errors']['Warning'][] = "<b>My WARNING</b> [$errno] $errstr<br />";
    break;

case 8: // notice
    if(isset($_REQUEST['ajax']) || isset($_REQUEST['ajaxAccess']) )         {
        $_SESSION['Errors']['Notice'][]="<b>My NOTICE</b> [$errno] $errstr $errfile $errline<br />";
        //json_encode($_SESSION);
        }

 //        else $error.= "<b>My NOTICE</b> [$errno] $errstr $errfile $errline<br />\n";
    break;

default:
 //        $error.= "Unknown error type: [$errno] $errstr<br />\n";
    break;
}

/* Don't execute PHP internal error handler */
return true;
 }

 $old_error_handler = set_error_handler("myErrorHandler");

The problem $errno is a number and does not match any of the option below

Do I probably have to changing something in configuration to have a string like that and make it works?

Thanks!

  • 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-06-04T11:28:54+00:00Added an answer on June 4, 2026 at 11:28 am

    Your code will only handle errors triggered by you – errors caused by a call to trigger error(). In order to catch errors thrown by regular PHP functions and actions, you need to handle those constants as well, most notably E_WARNING and E_NOTICE (you cannot handle E_ERROR).

    You can easily modify your switch to match those as well:

    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:
          $error= "<b>My ERROR</b> [$errno] $errstr<br />\n";
          $error.= "  Fatal error on line $errline in file $errfile";
          $error.= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
          $error.= "Aborting...<br />\n";
          $_SESSION['Errors']['Errors'][] = $error;
          // exit(1);
          break;
        case E_WARNING:
        case E_USER_WARNING:
          $_SESSION['Errors']['Warning'][] = "<b>My WARNING</b> [$errno] $errstr<br />";
          break;
        case E_NOTICE:
        case E_USER_NOTICE: // notice
          if(isset($_REQUEST['ajax']) || isset($_REQUEST['ajaxAccess']) )         {
            $_SESSION['Errors']['Notice'][] = "<b>My NOTICE</b> [$errno] $errstr $errfile $errline<br />";
            // json_encode($_SESSION);
          }
          // else $error.= "<b>My NOTICE</b> [$errno] $errstr $errfile $errline<br />\n";
          break;
        default:
          // $error.= "Unknown error type: [$errno] $errstr<br />\n";
          break;
      }
    
      /* Don't execute PHP internal error handler */
      return true;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Everybody i asked this question few hours ago C# get username from string.
Hello everybody I have a question: I have a array String[] parte and I
Suppose I have String str=Hello $everybody$. How $are$ you $all$; From above string, I
Hello everybody I've recently asked this question and I've given up with the 'replace
Hello everybody Well my question is about sql commands... If I have 2 tables
Hello everybody and sorry for the rather confusing question-title. I have a Hibernate Class
Hello Everybody! I got the following error, while trying to test a code for
Hello everybody With EF4, i can map a EDMX function (with update model from
Note: This question is posted here hello everybody, I have a predefind list of
Hallo and good sunday to everybody. I need to select N random records from

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.