Examples TOCexamples

Display handler - part 3.

$Date: 2004/08/07 14:28:59 $

 Table of contents

Introduction

This example requires :


This example will show you how to ignore logging system for all html_progress errors. But we keep errors into stack.

An error was volontary made on call of setAnimSpeed method (line 15). As it's an API error, default is to return error after it was raised, so only lines 23 thru 29 will be executed.

As we've decided to use our own error handler (lines 4 thru 11, and 12), variable $e (line15) will contains NULL and no more a PEAR_Error object as default.

display_errors

Print out errors (as a part of the output). For production web sites, you're strongly encouraged to turn this feature off, and use error logging instead. Keeping display_errors enabled on a production web site may reveal security information to end users, such as file paths on your Web server, your database schema or other information.

1 <?php ini_set('display_errors', false); ?>

log_errors

Log errors into a log file (server-specific log, stderr, syslog ...) As stated above, you're strongly advised to use error logging in place of error displaying on production web sites.

1 <?php ini_set('log_errors', true); ?>

 Render options

Default options below are used :

Only option changed is :

Legend for lineFormat: Legend for contextFormat:

[Top]

 Output

Array
(
    [code] => -100
    [params] => Array
        (
            [var] => $delay
            [was] => 10000
            [expected] => less or equal 1000
            [paramnum] => 1
        )

    [package] => HTML_Progress
    [level] => error
    [time] => 1091649873.02
    [context] => Array
        (
            [file] => d:\php\pear\html_progress\examples\errorstack\secure\display_errors-p3.php
            [line] => 15
            [function] => setanimspeed
            [class] => html_progress
            [type] => ->
            [args] => Array
                (
                    [0] => 10000
                )

        )

    [message] => invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"
)
Catch HTML_Progress error

[Top]

 PHP source syntax highlight

  1. <?php
  2. require_once 'HTML/Progress.php';
  3.  
  4. function _errorHandler($err)
  5. {
  6.     /**
  7.      * we don't want to manage progress error;
  8.      * none outputs (display, file, mail ...)
  9.      */
  10.     return;
  11. }
  12. $logger['error_handler'] = '_errorHandler';
  13.  
  14. $bar = new HTML_Progress($logger);
  15. $e = $bar->setAnimSpeed(10000);   // < - - - will generate an API error
  16.  
  17. if (is_object($e)) {
  18.     if (is_a($e,'PEAR_Error')) {
  19.         die('<h1>Catch PEAR_Error</h1>'.$e->toString());
  20.     }
  21. }
  22.  
  23. if ($bar->hasErrors()) {
  24.     $err = $bar->getError();
  25.     echo '<pre>';
  26.     print_r($err);
  27.     echo '</pre>';
  28.     die('<h1>Catch HTML_Progress error</h1>');
  29. }
  30. echo 'End of process';
  31. ?>

[Top]