phpsa
phpsa copied to clipboard
[Analyzer] Foreach - possible to write in referenced variable
Simple snippet:
$elements = [1,2,3,4,5];
foreach ($elements as $k => &$item) {
//....
}
$another = [1,2,3,4,5];
foreach ($another as $k => $item) {
}
https://3v4l.org/ndpr0
WIll be bug, $elements = [1,2,3,4,6]
Algoritm:
- Register Analyzer on foreach, if key or value
- Check if
$keyor$valueexist in theSymbolTable - If variable is referenced
Probably need to support unset operator if it's not working
Notice:
Variable should be renamed to protect writing to exists referenced variable