On Tue, Feb 6, 2024 at 11:19 AM Arvids Godjuks <arvids.godj...@gmail.com> wrote:
> On Tue, 6 Feb 2024 at 19:14, Larry Garfield <la...@garfieldtech.com> > wrote: > > Thank you Larry for this interesting summary - didn't remember there was > quite a bit a discussion around the topic prior. > > I lean on the "we have exceptions, just leave it be" side out of practical > reasons - the vast majority of OO code has standardized around the approach > and interoperability is high. It makes using code that's out there super > easy and predictable - almost nobody uses the "return false|0|-1" out there > (at least I haven't used code like that except the PHP's stdlib, and even > that has been changing little by little). It makes error handling > predictable, and considering the type of code we mostly write in PHP - most > of the time we leave the catching to the global top-level handler or > sentry/bugsnag/etc libraries. > Consistency is the word I want to highlight here. For better or for worse - > it's the method the PHP ecosystem arrived at and it's the predominant one. > Introducing a distinctly different method of error handling is going to > bring in wrappers around libraries that convert errors to one style or the > other, the application code can end up using different ways of error > handling, etc, etc. My approach is to grab a different language aka "the > right tool for the job" if I want to build things differently, that's why > we have so many programming languages and not just a few :) > > I'd put resources into optimising the VM and php engine to handle the > exceptions better and if there are improvements to be had there - do those > maybe? (I suspect JIT is also going to influence this a lot going forward). > > Sincerely, > Arvīds Godjuks > When what you have is a situation where a function or block of code goes "I know something fixable went wrong, but only the block above me in the execution stack knows what to do about it", Exceptions are extremely overkill. But they are the only "sane" option in PHP in a lot of situations. PHP simply doesn't have a language level structure to handle this VERY COMMON situation. The fact that people have standardized on Exceptions for this is not a point in favor of Exceptions. It is a sign of how much extra performance and semantic correctness we COULD provide to the language by improving this area of error handling. I don't know if the OP of this email thread was referring to this situation. It was honestly very difficult for me to follow what they were even asking for given the language barrier. But I am 1000% behind the problem space that Larry is describing. Exceptions are not a solution to that problem, they are duct tape. Jordan