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

False positive on truthy function-call conditions #1334

Closed
JanJakes opened this issue Aug 6, 2018 · 1 comment
Closed

False positive on truthy function-call conditions #1334

JanJakes opened this issue Aug 6, 2018 · 1 comment

Comments

@JanJakes
Copy link

JanJakes commented Aug 6, 2018

Summary of a problem or a feature request

When checking a method call result of type ?object in an IF or ternary operator and the using it (i.e. $a->getB() ? $a->getB()->getC()) the null type is probably not removed from the type combinator (see example below).

I would understand that behavior if there were some reasons that would make it hard to detect (like method can return something else on second call, etc.) but that seems not to be the case since $a->getB() !== null ? $a->getB()->getC() works.

Code snippet that reproduces the problem

Error: https://phpstan.org/r/bcbe85f9b434c0e1a4376925e89f06c3
This works: https://phpstan.org/r/e4e5a4574f1e61472681bb3d1b981b3a

Expected output

No errors.

This can of course easily be fixed by writing better code but for setting up PHPStan for legacy codebases it is not very useful.

@ondrejmirtes
Copy link
Member

Hi, see the discussion at #1157 and other linked issues.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 19, 2019
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