Skip to content
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

[Bleeding edge 0.12.83] Variable $body on left side of ?? is always null. #4814

Closed
ruudk opened this issue Apr 6, 2021 · 3 comments
Closed

Comments

@ruudk
Copy link
Contributor

ruudk commented Apr 6, 2021

Bug report

I've read https://phpstan.org/blog/precise-try-catch-finally-analysis and I think it's related to my issue.

Why is PHPStan so certain that $body will always be null? In my opinion, it can still be non-null if sendRequest does not throw but json_decode does.

Code snippet that reproduces the problem

https://phpstan.org/r/bd38b020-3e40-4a08-9032-9ba63ea3a40d

Expected output

No error.

@ruudk ruudk changed the title [Bleeding edge] Variable $body on left side of ?? is always null. [Bleeding edge 0.12.83] Variable $body on left side of ?? is always null. Apr 6, 2021
@ondrejmirtes
Copy link
Member

PHPStan doesn't know that json_decode can throw an exception in that case, will have to fix it.

@ondrejmirtes
Copy link
Member

Fixed by some previous commit, but I also added "dynamic throw type extensions" so that PHPStan understands when json_encode and decode throw an exception and when they don't: phpstan/phpstan-src@2bf30bf

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants