Search code examples
phperror-reporting

Count Number of PHP Warnings/Notices


Is there a way I can count the number of errors/notices/warnings that a script has come across whilst executing?

I wish to do something like this:

Warnings: 125
Notices: 234
..etc

Thanks


Solution

  • $warn = $notice = 0;  
    function f() { 
      global $warn, $notice; 
      $argv = func_get_args(); 
      switch($argv[0]) { 
        case E_WARNING: $warn++; break; 
        case E_NOTICE: $notice++; break; 
      }
    }
    set_error_handler('f', E_ALL);
    

    Expand as necessary :)