PEAR logo

HTML_CSS : The Definitive Guide

Custom Error Message Generation

Option: message_callback
Option: context_callback

There are two methods of HTML_CSS_Error designed for use with generating error messages efficiently. To use them, you must set the options below in the HTML_CSS class constructor (argument #2):

Option: message_callback

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

  1. <?php
  2. $messages = array(
  3.     HTML_CSS_ERROR_UNKNOWN =>
  4.         'unknown error',
  5.     HTML_CSS_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_CSS_Error::getBackTrace) gets an array of execution functions and discovers where the error was generated.

HTML_CSS : The Definitive Guide v 1.5.0 : January 15, 2008