PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/includes/error.inc.php

https://github.com/reshadf/Library
PHP | 85 lines | 53 code | 10 blank | 22 comment | 12 complexity | 7bccf43b1db16fff5cbe1d37dd31846a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * Error handler of FormHandler
  4. *
  5. * @package FormHandler
  6. * @author Teye Heimans
  7. */
  8. /**
  9. * catchErrors()
  10. *
  11. * Saves all PHP errors occoured in the form
  12. *
  13. * @return array: the array of occured errors
  14. * @access public
  15. * @author Teye Heimans
  16. */
  17. function &catchErrors()
  18. {
  19. static $errors = array();
  20. // Error event has been passed
  21. if ( func_num_args() >= 4 )
  22. {
  23. // @ error! do nothing
  24. if( ini_get('error_reporting') == 0 )
  25. {
  26. $var = null;
  27. return $var;
  28. }
  29. // dont save E_STRICT error messages
  30. if( defined('E_STRICT') && func_get_arg(0) == E_STRICT )
  31. {
  32. $var = null;
  33. return $var;
  34. }
  35. // save the error details
  36. $errors[] = array(
  37. 'no' => func_get_arg(0),
  38. 'text' => func_get_arg(1),
  39. 'file' => func_get_arg(2),
  40. 'line' => func_get_arg(3),
  41. 'vars' => (func_num_args() == 5 ? func_get_arg(4) : null )
  42. );
  43. // is it a ERROR? then display and quit
  44. if(func_get_arg(0) == E_USER_ERROR )
  45. {
  46. // display all errors first..
  47. foreach( $errors as $error )
  48. {
  49. switch ($error['no']) {
  50. case E_WARNING:
  51. case E_USER_WARNING:
  52. $type = 'Warning'; break;
  53. case E_NOTICE:
  54. case E_USER_NOTICE:
  55. $type = 'Notice'; break;
  56. case E_ERROR:
  57. case E_USER_ERROR:
  58. $type = 'Error'; break;
  59. default:
  60. $type = 'Warning ('.$error['no'].')'; break;
  61. }
  62. echo "<b>".$type."</b> ".basename($error["file"])." at ".$error["line"]." ". $error["text"]."<br />\n";
  63. }
  64. exit; // if we dont exit, php will
  65. }
  66. }
  67. // call for the errors. Return the reference
  68. if ( func_num_args() == 0 )
  69. {
  70. return $errors;
  71. }
  72. $var = null;
  73. return $var;
  74. }
  75. ?>