Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

register_shutdown_function() still outputs original error message

Tags:

php

I am trying to replace the built in php shutdown_function with a custom one.

It works perfectly, however, it still outputs the original error (built in error) above my new error message.

  <?php
  function shutdown_output() {
      $error = error_get_last();
      if($error !== NULL) {
          echo "ERROR";
          exit();
      } else {
          echo "NO ERROR";
      }
  }

  // Set the error reporting:
  register_shutdown_function('shutdown_output');

  // test.php does not exist, just here to get a critical error
  require_once("test.php");

  ?>

Any ideas?

like image 701
mauzilla Avatar asked Dec 19 '12 12:12

mauzilla


1 Answers

As already mentioned in comments, the use of register_shutdown_function is not going to override built-in error handling (the same way that set_error_handler doesn't either).

If you don't want to see the original message, disable the output of them in your php.ini using display_errors = 0. Or on the fly in your script using ini_set('display_errors', 0);.

like image 69
Rudi Visser Avatar answered Oct 02 '22 16:10

Rudi Visser