Are the user protocols PHP and log all possible errors that are mutually exclusive?

I use set_error_handler to override the default PHP error handling for the sole purpose of setting up error logging. but I came to the conclusion that simply cannot be configured error log and log all possible errors.

1) You can use set_error_handler () - but this function, quote from the php manual:

The following types of errors cannot be handled by a user-defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING and most E_STRICT

So - going this route - your custom log will not log these errors?

2) The second way is to use register_shutdown_function() and then run error_get_last() to get the error ... But - error_get_last() ... only gets the last error ... and although you may have some warnings and notifications in script runtime - this approach will allow you to log the most recent error, notification, warning - right?

So - IMHO - I see no way around this. It seems like if you want to have the most comprehensive error log - you just need to stick with php logger by default - right?

+6
source share
2 answers

The second way is to use register_shutdown_function () and then run error_get_last () to get the error ... But - error_get_last () ... gets only the last error

That's right, but if this is the type of error that the script killed, it really would be the right error inside your shutdown function. Just in case, you can check the type key in an array, which it returns for one of the exciting types. If it could be caught by another error handler, do not take any action.

FWIW, I have never seen E_CORE_ERROR , E_CORE_WARNING , E_COMPILE_ERROR or E_COMPILE_WARNING in the real world. Most compilation errors are parsing errors.

+4
source

1) That's right. This is due to the fact that these errors will stop the entire php process from working correctly and therefore it makes no sense to let the software self-repair. However, if you write software, it breaks down a lot, you have other problems besides logging.

2) Seems correct so far. But you also have set_error_handler() .

+2
source

Source: https://habr.com/ru/post/885753/


All Articles