Reputation: 65
I'm doing a small program which needs to read error meesage when errors occur.
For example, one operation triggered an error, and php log recorded it as:
PHP Fatal error: Smarty error: [in /mnt/n2my_web/templates/ja_JP/mail/reservation_create.t.txt line 16]: syntax error: mismatched tag {/if}. (Smarty_Compiler.class.php, line 2338) in /mnt/n2my_web/lib/Smarty/Smarty.class.php on line 1092
I know by setting ini_set('display_errors', '1'); the error message can be printed. But I need to read it, in order to format it.
By which means can I achieve this? Any answer is appreciated. :)
Upvotes: 0
Views: 1773
Reputation: 71384
Really the only way to can access any error information around a fatal error is to use register_shutdown_function()
to try to catch these errors and work with them before the script is terminated. This is not 100% reliable.
register_shutdown_function(function() {
$last_error = error_get_last();
if(!is_null($last_error) && $last_error['type'] === E_ERROR) {
/*
Do something with $last_error info.
$last_error will contain array with keys as follows:
['type']['message']['file']['line']
*/
}
});
Upvotes: 0
Reputation: 4430
Use this: http://www.php.net/manual/en/function.error-get-last.php , to handling error, I recommend you to just use custom exception and error handler
http://www.php.net/manual/en/function.set-exception-handler.php.
http://www.php.net/manual/en/function.set-error-handler.php
Upvotes: 2