Skip to content

Undefined array inside if condition or loop incorrectly marks other uses as read #210

@sirbrillig

Description

@sirbrillig

In the following example, we get a false negative:

function ifConditionWithUndefinedArrayAssignment($first) { if ($first) { $things[] = 'person'; // undefined array variable } return $things; // undefined variable, but not reported }

This one too:

function loopAndPushWithUndefinedArray($parts) { while ($part = array_shift($parts)) { $suggestions[] = $part; // undefined array variable } return $suggestions; // undefined variable, but not reported }

This is because #205 made it so that future uses of a variable after an array push are marked as defined. They need to only do that within the current if or else or loop scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions