-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Feature request
When using bool values as array keys, then these keys are implicitly casted to integers. This will cause problems when a strict comparison ===
is applied on these keys.
Example Code:
<?php
declare(strict_types=1);
$array = [
true => "true",
false => "false",
];
foreach ($array as $key => $value) {
var_export($key); echo " ";
}
The expected output (if boolean is assumed a valid array key) when running the code is
true
false
but because of int cast, the output is
1
0
Therefore PHPStan should output the following error messages for the given code:
------ -------------------------------------------------------------
Line test.php
------ -------------------------------------------------------------
6 Invalid array key type bool.
7 Invalid array key type bool.
------ -------------------------------------------------------------
Metadata
Metadata
Assignees
Labels
No labels