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 for is_numeric on partially numeric array items #2550

Closed
leongersen opened this issue Oct 31, 2019 · 2 comments
Closed

False positive for is_numeric on partially numeric array items #2550

leongersen opened this issue Oct 31, 2019 · 2 comments
Labels
Milestone

Comments

@leongersen
Copy link
Contributor

Bug report

When iterating an array that has both numeric and non-numeric values, PhpStan incorrectly reports Call to function is_numeric() with 1|'a' will always evaluate to false..

Code snippet that reproduces the problem

$apples = [1, 'a'];

foreach($apples as $apple) {
	if(is_numeric($apple)) {
		echo 'number';
	}
}

https://phpstan.org/r/25842e1a-5522-49d9-a0a5-a5722c6d8e15

Expected output

I expected no errors here, but PhpStan reports:

+--------------------------------------------------------------------------------+
| Line | test.php                                                                |
+--------------------------------------------------------------------------------+
| 6    | Call to function is_numeric() with 1|'a' will always evaluate to false. |
+--------------------------------------------------------------------------------+
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Oct 31, 2019
@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@1d27c61

@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 13, 2021
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

2 participants