-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Context
In recent versions of PHP, several so called errors migrated to be thrown as exceptions instead. The wording is confusing here, but the new class they created is named Error
and it does NOT inherit from Exception
but directly from Throwable
.
What does that mean?
Let's take an example, a division by zero.
In PHP 7, dividing by zero would generate an error of type E_Warning
and continue its execution.
In PHP 8, dividing by zero leads to a DivisionByZeroError
exception being thrown.
Let's imagine that division by zero happened when dispatching / rendering a page, for example in the Action
of a Controller
. Normally, in that context, any Exception
would "bubble up" through the Front
and the Standard
controllers dispatch()
methods and be handled properly by Zend - see https://github.com/zf1s/zf1/blob/7d4b8fe7848bacd0836cc7fa5f987c7b1f0fbb2e/packages/zend-controller/library/Zend/Controller/Front.php#L980C8-L980C33
The problem is, since a DivisionByZeroError
is NOT an Exception
it doesn't get catch by Zend and it ends up as a global exception.
What's the problem
Well, Errors
(and any Throwable
) are ending up as global unhandled exceptions, with no graceful "bailout" or anything and this is something that was introduced in PHP 7 but that is getting more frequent in PHP 8 and would probably continue like that in future PHP versions as the authors are laying more on exceptions than errors.
Proposition
I suppose we should consider revisiting those try/catch
in the controllers involved in dispatching, and change Exception
to Throwable
, or at the very least add the Error
alongside Exception
handling.
The minimal would be to adjust both the Front and the Standard controllers.
What do you think ?