PEAR Progress2 logo

HTML_Progress2 : The Definitive Guide

Custom Error Message Generation

Option: message_callback
Option: context_callback

In the default error class HTML_Progress2_Error there are two methods designed for use with generating error messages efficiently. To use them, you must set the options message_callback, and context_callback.

Option: message_callback

The default message handling callback (HTML_Progress2_Error::_getErrorMessage) get an array mapping error codes to error message templates, like so:

$messages = array(
    HTML_PROGRESS2_ERROR_UNKNOWN =>
        'unknown error',
    HTML_PROGRESS2_ERROR_INVALID_INPUT =>
        'invalid input, parameter #%paramnum% '
      . '"%var%" was expecting '
      . '"%expected%", instead got "%was%"'
);
     

Basically, if a variable name is enclosed in percent signs (%), it will be replaced with the value passed in the associative array.

Option: context_callback

The default context handling callback (HTML_Progress2_Error::getBackTrace) gets an array of execution functions and discovers where the error was generated.

HTML_Progress2 : The Definitive Guide v 1.0.0 : September 23, 2005