I am getting some false positive "A scalar of type 'x' used as an array" issue messages throughout the whole code.
The below example is a condensed example which results in a "A scalar of type 'null' used as an array" issue message for $vals['key02'].
You can test the sensitivity of the static analysis for this example, e.g. ...
- If you replace the value
null in line $vals['key01'] = null; by an int value (e.g. '1') you will get "A scalar of type 'int' used as an array".
- If you remove line
$vals['key01'] = $array['key01']; the issue message disappears.
function func(array $array): void
{
$vals = [];
if (!empty($array['key01'])) {
$vals['key01'] = $array['key01'];
} else {
$vals['key01'] = null;
}
$vals['key02'] = [];
if (!empty($array['key02'])) {
$vals['key02'][] = $array['key02']; // <-- Issue for $vals['key02']: "A scalar of type 'null' used as an array"
}
}