Caution: minimum PHP 5.2
<?php
// ========================
// Log PHP
// ========================
// Chamada quando vai ter Error
function call_fatal_handler()
{
// Déf.
$err_file = "nao_sei";
$err_str = "shutdown";
$err_no = E_CORE_ERROR;
$err_line = 0;
// Qual e a ultima error?
$error = error_get_last();
// Se tem, podems ler dados
if( $error !== NULL)
{
$err_no = $error["type"]; // Tipo
$err_file = $error["file"]; // O documento
$err_line = $error["line"]; // a linha
$err_str = $error["message"]; // o mensagem de error
// Aqui, podemos criar um email, salvar um BDD, ....
$content = call_format_error( $err_no, $err_str, $err_file, $err_line );
echo "<br>".$content;
}
}
function call_format_error( $errno, $errstr, $errfile, $errline )
{
$trace = print_r( debug_backtrace( false ), true );
$content = "<b>Error: </b>".$errstr."<br>\n";
$content .= "<b>Errno: </b>".$errno."<br>\n";
$content .= "<b>File: </b>".$errfile."<br>\n";
$content .= "<b>Line: </b>".$errline."<br>\n";
$content .= "<b>Trace: </b><pre>".$trace."</pre><br>\n";
return $content;
}
//-------------------------------------------------------------------------
register_shutdown_function( "call_fatal_handler" );
echo "Ola";
//$a = strstr();
echo "Display".$a; // $a nao tem definiçao
?>
I've forgotten a VERY important point, if instead of displaying the result, you try to do an insert in a BDD, it will not work. Because as the function is called at the end of the script, at this point the connection to the database is closed. The solution is to make another "sql_open" before your INSERT.