Home php error_get_last () Returns NULL

error_get_last () Returns NULL




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)
 // ...
  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);
Set_error_Handler ("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