sirbrillig / phpcs-variable-analysis

Find undefined and unused variables with the PHP Codesniffer static analysis tool.
Other
136 stars 14 forks source link

Assignment of an array element counts as a read #307

Open sirbrillig opened 1 year ago

sirbrillig commented 1 year ago

Discovered in https://github.com/sirbrillig/phpcs-variable-analysis/issues/305, an assignment of one element of an array does not get recorded as a write to that variable.

$foo = &$bar;
$foo['key'] = 1; // This counts as a "read" of $foo when it should be a "write".

I think in most cases this ends up not being an issue since clearly all the tests are passing but it could be the source of subtle bugs.