-
-
Notifications
You must be signed in to change notification settings - Fork 862
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
After calling a method with explicit exceptions, calls to methods with implicit exceptions are ignored #9878
Comments
Yes, this is expected behaviour. Once a try block contains explicit throw points, implicit throw points are ignored. It kind of assumes that once you start documenting your code with It's covered by this sentence in the article: https://phpstan.org/blog/precise-try-catch-finally-analysis
|
:/ That's very unfortunate. What's the purpose of Is it possible you could document this somewhere more discoverable than an old blog post, such as the config reference for exceptions? |
Why is it unfortunate? You can fix your code with: https://phpstan.org/r/ecf0ba5a-86e3-40cd-86cd-02cd47784945
Marking functions with |
Because it creates an all or nothing scenario where to avoid false positives, you have to have Thanks for the other examples! |
In my testing the issue you're experiencing was very rare. I tried other variants of this algorithm, they were much worse in practice. |
By "very rare" I mean I had to add correct |
This is a similar size legacy php code base. In the first case I'm looking at, because the If you're sure the behaviour is the best it possibly can be (thanks for your work!), I still believe there is opportunity to improve the documentation. What does absent
From the examples given above it, I think it'd be pretty fair to interpret this to mean that adding Wdyt about a couple of light edits to each post, PRs welcome? |
Yes, PRs always welcome :) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Take a look at this example:
This example reports "Variable $foo on left side of ?? is never defined", in the default configuration at https://phpstan.org/try and even with:
From my understanding,
implicitThrows
should treat every method that doesn't specify@throws void
as@throws Exception
.Here's an example of
testCatchException()
hitting the exception handler with$foo
sometimes defined: https://3v4l.org/dufRX.Code snippet that reproduces the problem
https://phpstan.org/r/d4c83865-5ed9-4080-961d-882ceb95cf15
Expected output
No issues should be reported, since
$foo
can be either undefined or 1, not only undefined.Did PHPStan help you today? Did it make you happy in any way?
Not so much today but many times before today :)
The text was updated successfully, but these errors were encountered: