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

If condition is always true (assignment array value after coalesce operator) #2093

Closed
vbelorus opened this issue Apr 26, 2019 · 5 comments
Closed
Labels
Milestone

Comments

@vbelorus
Copy link

vbelorus commented Apr 26, 2019

Bug report

Hi, I have such example in a code:

$missingArgs = [];
$args = ['username' => 'name', 'password' => 'password'];

$username = $args['username'] ?? $missingArgs[] = 'username';
$password = $args['password'] ?? $missingArgs[] = 'password';

if ($missingArgs) {
	//do something
}

Phpstan says that: If condition is always true.

Code snippet that reproduces the problem

https://phpstan.org/r/22616127-39a8-4bbd-874e-1bff9276da26
https://phpstan.org/r/11cebae9-023c-4ea4-bca4-69a03f1e2e50 (https://3v4l.org/Hkrk5)

Expected output

If condition is not always true

Could/should it be fixed in phpstan?

@ondrejmirtes
Copy link
Member

Hi, please check your code. The condition is really always true: https://3v4l.org/Sr5Xk

@vbelorus
Copy link
Author

@ondrejmirtes
Copy link
Member

I see the problem now, thanks.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Apr 26, 2019
@rskuipers
Copy link

rskuipers commented May 9, 2019

I'm running into this issue as well when doing an isset on an object with ArrayAccess: https://phpstan.org/r/60cebe59-957e-42fe-bbb0-e6b4961c1213 (https://3v4l.org/ZQo4i)

@ondrejmirtes
Copy link
Member

Fixed:

@lock lock bot locked as resolved and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants