-
-
Notifications
You must be signed in to change notification settings - Fork 947
False positive: Strict comparison using === between mixed and 0 will always evaluate to false. #6811
Copy link
Copy link
Closed
Description
Bug report
The error message "Strict comparison using === between mixed and 0 will always evaluate to false." seems to be a bug - if you compare the data type "mixed" to integer 0 then there is a possibility that it will be true: if the mixed value is exactly the integer 0.
Code snippet that reproduces the problem
I managed to condense my complicated code from https://github.com/pfrenssen/coder/blob/8.3.x/coder_sniffer/Drupal/Sniffs/Formatting/MultipleStatementAlignmentSniff.php to this snippet (sorry, the logic is a bit non-sensical, but I hope you get the point):
<?php declare(strict_types = 1);
$assignments = [];
for ($i = 0; $i < 10; $i++) {
$found = $_GET['x'];
if ($found === 0) {
$found = 1;
}
$assignments[$i] = [
'found' => $found,
];
}
foreach ($assignments as $assignment => $data) {
if ($data['found'] === 0) {
print "hello";
}
}https://phpstan.org/r/73b47e9e-5081-4cd3-a309-5cc2845bebd1
Expected output
no output because code is correct.
Did PHPStan help you today? Did it make you happy in any way?
PHPStan is getting a hold in the Drupal community, I really like seeing that!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels