I am revising a PHP project that is necessary because of a massive redesign in the database. Therefore, the project should use the latest PHP version, which at the moment of writing is version 8. I am also using an OOP approach with namespace, so the project can benefit from features like autoloading in the future.
In the new classes I wrote, I need to throw errors. But in PHP 8, there are so many ways to do this. I could use trigger_error or exceptions or the error class and its specific variants like value error. Now I am unsure which to choose. Currently I have a mixture of exceptions and trigger_error in the code.
I have a custom handler defined for both exception and "old" errors, which writes the errors to a log file so I can fix them (if possible).
So what should I use to write a future-proof code? Unfortunately I couldn't find anything in the PHP docs about this. Also my web research didn't bring any useful result unfortunately. Is there a best approach rule?