What is PHP error handling and exception handling?
Why Interviewers Ask This
Mid-level PHP roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
PHP has two error systems. The traditional PHP error system generates errors, warnings, and notices (E_ERROR, E_WARNING, E_NOTICE) controlled by error_reporting() and handled by a custom error handler set with set_error_handler(). The modern exception handling system uses try-catch-finally blocks, just like Java. Throw: throw new InvalidArgumentException("Invalid input");. Catch: catch (InvalidArgumentException $e) { log($e->getMessage()); }. PHP 7+ unified them: Error (PHP fatal errors) and Exception both implement the Throwable interface, so you can catch both with catch (Throwable $t). Use set_exception_handler() for a global fallback exception handler.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong PHP candidates.