Skip to content

[ISSUE] False positive "A scalar of type 'x' used as an array" issue messages #185

@menturion

Description

@menturion

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"
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions