Abs
Abs

Reputation: 57916

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

Upvotes: 2

Views: 2086

Answers (2)

TML
TML

Reputation: 12966

$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 :)

Upvotes: 7

Tom Haigh
Tom Haigh

Reputation: 57815

You could use set_error_handler() to define a custom error handler which increments a global counter as well as logging/displaying the error.

Upvotes: 0

Related Questions