According the PHP Manual: Internal PHP functions mainly use Error reporting, only modern Object oriented extensions use exceptions. However, errors can be simply translated to exceptions with ErrorException
The 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 the default error reporting. My question is, is this an encouragement or merely an option for us?
Moreover, which is a better practice, use Exception alone like the above example, or use both Exception (set_exception_handler) and Error reporting (set_error_handler) alongside with each other?
Short answer: No. That are two different functions.
Long answer: It's not meant to replace but to make use of. set_exception_handler
Docs is used for exceptions and set_error_handler
Docs for errors. That are two different pair of shoes.
See as well:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With