-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Front controller won't catch exceptions of type Error #201
Comments
I would also argue that, as we are moving forward with PHP 8, we are trying to strongly type our code. But as we do, there are inevitable errors that we discover in production with real life data. We had an example like that, here is a simplified version where we decided to strongly type the function myFunction(array $arg) {
// ...
}
myFunction("oh no!"); // throwing a TypeError In PHP 7 and 8 it throws a |
Another side effect we experienced was that in our setup we have both Monolog and Sentry integrated. And because Zend wouldn't catch the The problem is, Monolog and Sentry each have dedicated Error and Exception handlers, so we ended up with both Monolog and Sentry reporting the same What a mess. |
@fredericgboutin-yapla do you think that could help? Shardj/zf1-future#90 |
It seems incomplete to me. It is missing the Standard dispatcher modifications following the Front dispatcher.
Hum, symfony/polyfill#101 But at least we could polyfill the
I see... I really like the stability of this project compared to zf1-future, thought. But you are probably right. |
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 fromException
but directly fromThrowable
.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 aController
. Normally, in that context, anyException
would "bubble up" through theFront
and theStandard
controllersdispatch()
methods and be handled properly by Zend - see https://github.com/zf1s/zf1/blob/7d4b8fe7848bacd0836cc7fa5f987c7b1f0fbb2e/packages/zend-controller/library/Zend/Controller/Front.php#L980C8-L980C33The problem is, since a
DivisionByZeroError
is NOT anException
it doesn't get catch by Zend and it ends up as a global exception.What's the problem
Well,
Errors
(and anyThrowable
) 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 changeException
toThrowable
, or at the very least add theError
alongsideException
handling.The minimal would be to adjust both the Front and the Standard controllers.
What do you think ?
The text was updated successfully, but these errors were encountered: