LSerror : Add PHP error handler

This commit is contained in:
Benjamin Renard 2014-11-20 12:04:03 +01:00
parent 1e37b2f870
commit bb09c81243
2 changed files with 48 additions and 1 deletions

View file

@ -171,11 +171,57 @@ class LSerror {
} }
return; return;
} }
/**
* PHP error handler (see set_error_handler() function doc)
**/
public function errorHandler($errno, $errstr, $errfile, $errline) {
self :: addErrorCode(-2,"Error ".self :: convertPHPErrorNo($errno)." occured in file $errfile (line : $errline) : $errstr");
if ( E_RECOVERABLE_ERROR===$errno ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
return False;
}
/**
* Convert PHP error number to string
*
* @param[in] $errno int Error number
*
* @retval string Corresponding error name
**/
public function convertPHPErrorNo($errno) {
$error_levels=array (
1 => "ERROR",
2 => "WARNING",
4 => "PARSE",
8 => "NOTICE",
16 => "CORE_ERROR",
32 => "CORE_WARNING",
64 => "COMPILE_ERROR",
128 => "COMPILE_WARNING",
256 => "USER_ERROR",
512 => "USER_WARNING",
1024 => "USER_NOTICE",
2048 => "STRICT",
4096 => "RECOVERABLE_ERROR",
8192 => "DEPRECATED",
16384 => "USER_DEPRECATED",
32767 => "ALL",
);
if (isset($error_levels[$errno])) {
return $error_levels[$errno];
}
else {
return "UNKNOWN_ERROR";
}
}
} }
/* /*
* Error Codes * Error Codes
*/ */
LSerror :: defineError(-1,_("Unknown error!")); LSerror :: defineError(-1,_("Unknown error : %{error}"));
LSerror :: defineError(-2,_("PHP error : %{error}"));
?> ?>

View file

@ -191,6 +191,7 @@ class LSsession {
if(!self :: loadLSclass('LSerror')) { if(!self :: loadLSclass('LSerror')) {
return; return;
} }
set_error_handler(array('LSerror','errorHandler'),E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING);
self :: defineLSerrors(); self :: defineLSerrors();
return true; return true;
} }