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:

  1. <?php
  2. $messages = array(
  3.     HTML_PROGRESS2_ERROR_UNKNOWN =>
  4.         'unknown error',
  5.     HTML_PROGRESS2_ERROR_INVALID_INPUT =>
  6.         'invalid input, parameter #%paramnum% '
  7.       . '"%var%" was expecting '
  8.       . '"%expected%", instead got "%was%"'
  9. );
  10. ?>

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 2.4.0 : April 20, 2007