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

LHS always true - not necessarily #1746

Closed
josephzidell opened this issue Jan 2, 2019 · 5 comments
Closed

LHS always true - not necessarily #1746

josephzidell opened this issue Jan 2, 2019 · 5 comments
Labels
Milestone

Comments

@josephzidell
Copy link
Contributor

In this code snippet, I am iteratively redetermining whether a bool variable is still true (sort of like an array_reduce, but more complex).

PHPStan is reporting Left side of && is always true.

Am I doing something wrong?

@ondrejmirtes
Copy link
Member

Yeah, it's a bug because of the break. This is the workaround: https://phpstan.org/r/c37ea4c0-1b03-4e0b-9b11-5cbdabef9e8c

@josephzidell
Copy link
Contributor Author

Easy enough. I'll leave this issue open for you to handle. Thanks! 💯

@dereuromark
Copy link
Contributor

dereuromark commented Jan 8, 2019

Another regression:

509 Result of || is always true.

on

	protected function propertyInUse(array $tokens, $closeTagIndex, $variable) {
		$property = substr($variable, 1);

		$i = $closeTagIndex + 1;
		while (isset($tokens[$i])) {
			...
			if ($tokens[$i]['code'] !== T_STRING || $tokens[$i]['content'] !== $property) { // 509
				$i++;
				continue;
			}

thats invalid reporting here.

workaround as assignment works:

$token = $tokens[$i];
if ($token['code'] !== T_STRING || $token['content'] !== $property) {

but this is super annoying to be done everywhere to silence this wrong reporting.

@ondrejmirtes
Copy link
Member

Looking at the original example https://phpstan.org/r/2026695c-98ae-49f9-9e3f-f88c1051c6f0 I think PHPStan might be actually correct. Because the foreach is terminated (broken out of) when $isMatch is false, it really only can be true on line 12, right?

@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 Mar 16, 2022
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