Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sirbrillig opened this issue Jun 22, 2020 · 1 comment
Open
Labels

Comments

@sirbrillig
Copy link
Owner

sirbrillig commented Jun 22, 2020

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. 😩

@sirbrillig
Copy link
Owner Author

I think this is actually more easily fixable than I thought. Right now (unless I'm missing something) the only reason we track pass-by-reference functions is in order to determine if a function call's use of an undefined variable can count as defining that variable. A common example is $matches in preg_match(). Therefore, we can fix this by removing all the pass-by-reference arguments and functions from getPassByReferenceFunction() that do not allow this.

This may take a while, but I've started the process in #186 by removing the array functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant