On PHP5 it makes a whole lot of sense having both set_exception_handler()
and set_error_handler()
defined.
However, on PHP7 all (most?) errors are now exceptions. So, what's the point on defining both handlers, if even errors would pass by the exception handler instead?
I see there's a note on PHP7 new Error
class in the exception handler doc, but there's no reference to the fact there's no plain errors anymore, but Throwable
s, in the error handler function.
Since PHP 7, most errors are reported by throwing
Error
exceptions, which will be caught by the handler as well. BothError
andException
implements theThrowable
interface. [source]
Converting errors into exception is done by calling set_error_handler() and throw new ErrorException() in there...
Many fatal and recoverable fatal errors have been converted to exceptions in PHP 7. These error exceptions inherit from the Error class, which itself implements the Throwable interface (the new base interface all exceptions inherit).
Like any other exceptions, Error objects can be caught using a try/catch block. Or you can use Throwable interface to catch all exceptions.
You can use php trigger_error('test error')
to see what happen when error is not handled by php set_exception_handler()
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