Skip to content

Assignment by reference is not declaration for arrays and objects #184

Open
@sirbrillig

Description

@sirbrillig
function whileLooopAssignWithUndefinedShift() {
  $suggestions = [];
  while ($part = array_shift($parts)) { // undefined variable parts
    $suggestions[] = $part;
  }
  return $suggestions;
}

$parts is not marked as undefined. This is happening because array_shift counts as an assignment... but clearly not all assignments should be counted as definitions if the expected variable is an array or object.

This may mean that we need to annotate all the pass-by-reference functions in both PHP and WordPress by what types of variables they expect. 😩

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions