Explain how PHP handles errors vs. exceptions since PHP 7/8.
Last updated
Since PHP 7 most fatal errors are thrown objects. Both
Error(engine faults likeTypeError,DivisionByZeroError) andException(application conditions) implementThrowable.Use
catch (Throwable $e)to handle both together. Userland classes can't implementThrowabledirectly and must extend one of the two.Warnings and notices (
E_WARNING,E_NOTICE) are not throwables. Convert them viaset_error_handler()throwing anErrorException.