Home php error_get_last () Returns NULL

error_get_last () Returns NULL

Author

Date

Category

For example, do this:

$ var = ss; // indefinite constant, for example
file_put_contents ('1.Log', Var_Export (Error_Get_Last (), True));

In the end I get null

Example of a real code:

function error_handler ($ errno, $ errstr, $ errfile, $ errline)
{
 // ...
}
FUNCTION FATAL_ERROR_HANDLER ()
{
  CDIR ($ _ Server ['document_root']. '/dsm2.7f2_local/dsm2');
  $ error = error_get_last ();
  If ($ error & amp; & amp; $ error ['type'] == E_ERROR) {
    SenderRorMessage ('[email protected] ',' error ',' Fatal Error! ');
    Error_Handler ($ Error ['Type'], $ error ['message'], $ error ['file'], $ error ['line']);
  }
}
Function Senderrormessage ($ email, $ Subject, $ MSG)
{
  // ...
}
Error_Reporting (-1);
INI_SET ('DISPLAY_ERRORS', 'OFF');
Set_error_Handler ("Error_Handler");
REGISTER_SHUTDOWN_FUNCTION ('FATAL_ERROR_HANDLER');

Answer 1, Authority 100%

There is in general interception of any errors other than fata belts using set_error_handler . Fatal can be intercepted using Register_Shutdown_Function . There is still set_exception_handler – for a special type of errors “Non-accomplished exceptions.” Interceptors need to be determined at the beginning of the program – for example, with the design of the object like Logger.

Well, manually exclusion is intercepted using try {..} Catch (Exception $ E) {/ * Interception * /} – If you do not intercept, it will capture set_error_handler or set_exception_handler , but you need to remember that the fatals, notities, stricters (types of errors) are not related to exceptions, sometimes the varnings do not belong.

Here all the processing of errors in PHP – if you start writing in the log of all errors and notice: helps well, allows you to produce a properly working code.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions