<?php
  define
("LOG_NAME""error_log"); 

  
// user defined error handling function
  
function userErrorHandler($errno$errmsg$filename$linenum$vars)
  {
    
// http://www.php.net/manual/en/ref.errorfunc.php#id3446732
    // timestamp for the error entry
    // for a format like "08-Jan-2007 17:09:55", use "d-M-Y H:i:s"
      // for other formats, see: http://www.php.net/date
    
$dt date("d-M-Y H:i:s O");

    
// define an assoc array of error string
    // in reality the only entries we should
    // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
    // E_USER_WARNING and E_USER_NOTICE
    
$errortype = array (
                
E_ERROR              => 'Error',
                
E_WARNING            => 'Warning',
                
E_PARSE              => 'Parsing Error',
                
E_NOTICE             => 'Notice',
                
E_CORE_ERROR         => 'Core Error',
                
E_CORE_WARNING       => 'Core Warning',
                
E_COMPILE_ERROR      => 'Compile Error',
                
E_COMPILE_WARNING    => 'Compile Warning',
                
E_USER_ERROR         => 'User Error',
                
E_USER_WARNING       => 'User Warning',
                
E_USER_NOTICE        => 'User Notice',
                
E_STRICT             => 'Runtime Notice',
                
E_RECOVERABLE_ERROR  => 'Catchable Fatal Error'
                
);
    
// set of errors for which a var trace will be saved
    
$user_errors = array(E_USER_ERRORE_USER_WARNINGE_USER_NOTICE);
   
    if (
array_key_exists($errno$user_errors)) {
      
// compose an error like the Apache ones
      
$err="[".$dt."] PHP ".$errortype[$errno].": ".$errmsg." in ".$filename." on line ".$linenum."\n";
      
// echo $err; //test

      // save to the error log
      
error_log($err3LOG_NAME);
    }
  }
  
  
set_error_handler("userErrorHandler");
?>