Daje pod ocene Error Handler:

  1. <?php
  2. class Error
  3. {
  4. private static $instance;
  5.  
  6. private function __construct( $eErrorNo, $eErrorStr, $eFile, $eLine, $eContext )
  7. {
  8. echo '<table cellspacing="0" cellpadding="0" style="font-family: verdana; font-size: 10px; border: 1px solid #000000;"><tr><td>';
  9. echo 'Blad: ' . $this->getError($eErrorNo) . '<br />
  10. Plik: ' . $eFile . '<br />
  11. Linia: ' . $eLine . '<br />
  12. Tresc: ' . $eErrorStr;
  13. echo '</td></tr></table>';
  14.  
  15. $eTxtLog = date('d.m.Y H:i:s') . '|*|' . $this->getError($eErrorNo) . '|*|' . $eFile . '|*|' . $eLine . '|*|' . $eErrorStr;
  16. $this->Add2Log( $eTxtLog );
  17. }
  18.  
  19. public static function ErrorHandler( $eErrorNo, $eErrorStr, $eFile, $eLine, $eContext )
  20. {
  21. if (!isset(self::$instance)) 
  22. {
  23. $class = __CLASS__;
  24. self::$instance = new $class($eErrorNo, $eErrorStr, $eFile, $eLine, $eContext);
  25. }
  26.  
  27. return self::$instance;
  28. }
  29.  
  30.  
  31. private function Add2Log( $eTxtLog )
  32. {
  33. $eTxtLog = $eTxtLog . "\r\n";
  34. $fp = fopen('log.txt','a');
  35. fwrite($fp, $eTxtLog);
  36. fclose($fp);
  37. }
  38.  
  39. private function getError( $eErrorNo )
  40. {
  41.  
  42. $aErrors = array(
  43.  E_ERROR => 'Error',
  44.  E_WARNING => 'Warning',
  45.  E_PARSE => 'Parsing Error',
  46.  E_NOTICE => 'Notice',
  47.  E_CORE_ERROR => 'Core Error',
  48.  E_CORE_WARNING => 'Core Warning',
  49.  E_COMPILE_ERROR => 'Compile Error',
  50.  E_COMPILE_WARNING => 'Compile Warning',
  51.  E_USER_ERROR => 'User Error',
  52.  E_USER_WARNING => 'User Warning',
  53.  E_USER_NOTICE => 'User Notice',
  54.  E_STRICT => 'Runtime Notice'
  55.  );
  56.  
  57. return $aErrors[$eErrorNo];
  58. }
  59. }
  60. ?>


I jego wykorzystanie:

  1. <?php
  2. set_error_handler(array('Error','ErrorHandler'));
  3. ?>


Zalezy mi abyscie wskazali bledy, podsuneli pomysly, inne rozwiazania. Nie jestem pewien czy tak powinien wygladac Error Handler.