In the return code case, we're using if/then to handle error situations.
In the exception code, we're using try/catch.
With respect to spaghetti, they're literally the same thing, just differently indented...
In the return code case, we're using if/then to handle error situations.
In the exception code, we're using try/catch.
With respect to spaghetti, they're literally the same thing, just differently indented...
edit: or the PHP special of hitting an error down the stack and again just dying without passing the message up the chain. That is no way to work.
Oh, absolutely. That's how I do it too. Unfortunately, warnings and notices are still a thing in PHP 7. So the best practice is to just install an error handler that turns these into exceptions. They they are either handled by code, or by a catch-all handler.
This is in fact what I've implemented SlashTrace to do by default: https://github.com/slashtrace/slashtrace/blob/master/src/Err...