"Dead catch" with assert() and AssertionError #13103
Replies: 2 comments
-
See https://www.php.net/manual/en/function.assert.php What are you trying to achieve with assert()? Its usually a bad idea to narrow stuff only in dev but not in production |
Beta Was this translation helpful? Give feedback.
-
I saw that the assert.exception setting has been deprecated, but its default value has also been changed from I am changing the behavior of a fundamental component of the project. It should now throw an exception if However, I just saw that instead of this try {
assert($value === null);
} catch (\AssertionError $e) {
throw new CorrectException();
} I could do it like that assert($value === null, new CorrectException()); But I am still wondering about PHPStan's behavior in the example of my initial post. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Please take a look at this example: https://phpstan.org/r/9d7d8c45-b6b9-4e8b-8242-2d69f49604eb
Why does PHPStan not consider that
assert()
can throw\AssertionError
? Is it because assertions are normally not enabled in production?Beta Was this translation helpful? Give feedback.
All reactions