I have to work with low-quality legacy PHP code. Because of poor architecture and exception handling, often happens, that an error (core \Exception
or \RuntimeException
or \TypeError
) is thrown and caught at some moment, but ignored and instead replaced with hardcoded result, which hides original error. Because of high code duplication, it is hard to check all catch
-blocks. Also, I can not just refactor all catch
-blocks because of codebase size and VCS policy.
Thus, to debug errors, I'd like to replace core \Exception::__construct
(and \Error::__construct
) for runtime session on my local machine, so that every time any exception is created, my custom code was called (f.e. trigger error and use my error_handler). I do not want to simply override them in child classes, but replace in original core classes (maybe with ReflectionAPI?).
Please note: this is not about common question "how to convert errors to exceptions", but exactly vice versa.
Is it possible for PHP7.1 and higher?