Skip to content

False positive for is_numeric on partially numeric array items #2550

@leongersen

Description

@leongersen

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. |
+--------------------------------------------------------------------------------+

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions