HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]
Prev Next
HTML_Progress::hasErrors
returns count of API error

Synopsis

require_once 'HTML/Progress.php';

integer HTML_Progress::hasErrors()

Description

This method tell whether there are errors into HTML_Progress stack, and how much.

Note

( HTML_Progress >= 1.2.0RC3 )

This function can be called statically.

The HTML_Progress error stack follows the same PEAR_ErrorStack structure: associative array with keys 'code', 'params', 'package', 'level', 'time', 'context'.

See

HTML_Progress::raiseError, HTML_Progress::getError

Example

Example below will produce a such output on browser:

Error: invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"
---------------------------------------------------------------------------------------------------
Function: html_progress::setanimspeed
File: d:\php\pear\html_progress\tutorials\html_progress\examples\display_errors-p6.php
Line: 55 

Catch HTML_Progress error 
invalid input, parameter #1 "$delay" was expecting "less or equal 1000", instead got "10000"

  1. <?php
  2. require_once 'HTML/Progress.php';
  3.  
  4. function _pushCallback($err)
  5. {
  6. // now don't die if the error is an exception, it will be ignored
  7. if ($err['level'] == 'exception') {
  8. return HTML_PROGRESS_ERRORSTACK_IGNORE;
  9. }
  10. }
  11. function _errorHandler($err)
  12. {
  13. global $options;
  14.  
  15. $display_errors = ini_get('display_errors');
  16.  
  17. if ($display_errors) {
  18. $lineFormat = $options['lineFormat'];
  19. $contextFormat = $options['contextFormat'];
  20.  
  21. $file = $err['context']['file'];
  22. $line = $err['context']['line'];
  23. $func = $err['context']['class'];
  24. $func .= $err['context']['type'];
  25. $func .= $err['context']['function'];
  26.  
  27. $context = sprintf($contextFormat, $file, $line, $func);
  28.  
  29. printf($lineFormat."<br />\n", ucfirst($err['level']), $err['message'], $context);
  30. }
  31. }
  32. $logger['push_callback'] = '_pushCallback';
  33. $logger['error_handler'] = '_errorHandler';
  34.  
  35. $options = array(
  36. 'lineFormat' => '<b>%1$s</b>: %2$s <hr>%3$s',
  37. 'contextFormat' => '<b>Function</b>: %3$s<br/><b>File</b>: %1$s<br/><b>Line</b>: %2$s'
  38. );
  39. $logger['handler']['display'] = array('conf' => $options);
  40.  
  41. $bar = new HTML_Progress($logger);
  42. $e = $bar->setAnimSpeed('100'); // < - - - will generate an API exception
  43.  
  44. if (is_object($e)) {
  45. if (is_a($e,'PEAR_Error')) {
  46. die('<h1>Catch PEAR_Error API exception</h1>'. $e->toString());
  47. }
  48. }
  49. if (HTML_Progress::hasErrors()) {
  50. $err = HTML_Progress::getError();
  51. echo '<pre>';
  52. print_r($err);
  53. echo '</pre>';
  54. die('<h1>Catch HTML_Progress exception</h1>');
  55. }
  56.  
  57. $e = $bar->setAnimSpeed(10000); // < - - - will generate an API error
  58.  
  59. if (is_object($e)) {
  60. if (is_a($e,'PEAR_Error')) {
  61. die('<h1>Catch PEAR_Error API error</h1>'. $e->toString());
  62. }
  63. }
  64. if (HTML_Progress::hasErrors()) {
  65. $err = HTML_Progress::getError();
  66. die('<h1>Catch HTML_Progress error</h1>'.$err['message']);
  67. }
  68. ?>

Prev Up Next
HTML_Progress::raiseError Reference Guide HTML_Progress::getError

Documentation generated on Sun, 12 Sep 2004 20:23:14 +0200 by phpDocumentor 1.3.0RC3