![]() HTML_Progress2 : The Definitive Guide
|
There are many scenarios in which fine-grained control over error raising is absolutely necessary.
The first level to control error generation is the
php.ini
directives display_errors and
log_errors. When these directives are set to
TRUE
, then browser and file outputs are effective.
![]() |
Tip |
---|---|
If you want to ignore all errors raised (no display, no logs) and avoid to include PEAR core class, then you should have something like :
<?php require_once 'HTML/Progress2.php'; function myErrorHandler() { return null; } $errorConf = array('error_handler' => 'myErrorHandler'); $meter = new HTML_Progress2($errorConf); // ... ?> |
![]() |
Caution |
---|---|
The previous example will ignore display and logging activity, but NEVER ignore internal stack error. In other words, you'll keep always minimum information in the progress stack error. These informations are :
array('code' => $code, 'level' => $level, 'params' => $params); /* $code : API error code (HTML_PROGRESS2_ERROR_* constant value) $level : API error level (warning, error, exception) $params: API context execution parameters hash (function argument: name, type, value) */So, these lines are always true (in error condition): $meter = new HTML_Progress2(); // ... if ($meter->hasErrors() > 0) { // do something on error ... } |
It's up to you to choose your programming way. Just keep in mind this warning, in case of code evolution (error handler configuration). Behavior could change, and you won't keep backward compatibility.
With push_callback option, you can decides to stop script execution (as done with exceptions by default: returns
PEAR_ERROR_DIE
constant), or continue without filtering (returns
NULL
).
If you want to write your own callback function for the push_callback option, this one should have two arguments: first one will get the error code, and second will get error level. These are all the necessary informations to do a filtering. Example that follow show how to be aware that a deprecated function is used in a script.
<?php require_once 'HTML/Progress2.php'; function myErrorFilter($code, $level) { if ($code === HTML_PROGRESS2_ERROR_DEPRECATED) { error_log('script: '.__FILE__.' still used a deprecated function', 1, 'admin@yoursite.com'); } return null; } $errorConf = array('push_callback' => 'myErrorFilter'); $meter = new HTML_Progress2($errorConf); // ... ?>
HTML_Progress2 : The Definitive Guide | v 1.0.0 : September 23, 2005 |