There are many ways to get the error log in PHP, below I give you a brief introduction of how to solve such problems, the following through the code to show you, hope to help everyone.
<?php
error_reporting (0);
Register_shutdown_function ($err = ' my_error_handler ') or Set_error_handler ($err, E_all); Register two functions at the same time.
Function parameter error
$original = unserialize (Array (423142,2134234));
Not to 0 except
Echo 1/0;
Nonexistent array index
echo $_get[' AA '];
A constant php_e that does not exist
;
The nonexistent variable
echo $var;
Function parameter error
strlen (Array (2434));
Function parameter error
MD5 (Array (1));
User Custom error
trigger_error (' Safdds ', e_user_notice);
nonexistent function PHP interrupt
//TES ();
Nonexistent method php interrupts
$ts = new AFSD ();
function My_error_handler ($errno =0, $errstr =0, $errfile =0, $errline =0) {
if ($errno && $errfile) {
if (true) {
$earr = array ();
$earr [' type '] = $errno;
$earr [' message '] = $ERRSTR;
$earr [' file '] = $errfile;
$earr [' line '] = $errline;
}
} else{
$earr = Error_get_last ();
}
Echo ' <pre> ';
Print_r ($earr);
return array ();
}
For PHP errors, we must know clearly, the type is divided into several types, when the trigger, what the return value is.
If you do not distinguish between warnings, errors, suggestions, hints, and other types of fine type, then we can understand that there are two types of error in PHP:
One is to force an interrupt program error. If the error, the method does not exist, and so on. Low memory, timeout
A non-disruptive error. such as warning, prompt these
Where getting the interrupt program error requires using the Register_shutdown_function function, registering a memory function, and then getting the error message, which only gets the first error row, such as multiple nonexistent functions, it can only get the first error. This is actually good, you fix one, it will move to the next.
Non-disruptive error, if used: register_shutdown_function, it will become extremely difficult to operate, only to get the first hint or warning, then we need to Set_error_handler, each touch error level constants, you will call the error function once, and you can get the error log inside. However, this function takes the Error_get_last function, so you'll find that the error_get_last is returned to NULL, all passed in by the arguments.
Two functions together, you can get 99% of the error of the program, which for the PHP program, is the snow to send a lighter.
Try running the example above.
Through the combination of code and text to the error log in PHP to get the method of collation, I hope that in the future, we will encounter such problems in the work of help.