Is set_exception_handler set to replace set_error_handler?

According to the PHP Manual : PHP's internal functions mainly use error reporting, but only modern object-oriented extensions use exceptions. However, errors can simply be thrown to exceptions with an ErrorException

Example provided in ErrorException:

<?php function exception_error_handler($errno, $errstr, $errfile, $errline ) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); 

It seems to allow using Exceptions instead of default error reporting. My question is, is this an encouragement or just a choice for us?

Also, what is the best practice, use the exception yourself, as in the above example, or use both the exception (set_exception_handler) and the error report (set_error_handler) next to each other?

+4
source share
1 answer

Short answer: None. These are two different functions.

Long answer: it is not intended to be replaced, but to be used. set_exception_handler Documents are used for exceptions and set_error_handler Documents for errors. These are two different pairs of shoes.

See also:

+7
source

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


All Articles