Closed ghnp5 closed 1 year ago
Interesting! It looks like something to do with the array access which is breaking this. The bug does occur in the expression:
do_something(fn($array, $needle) => $array[2] === $needle);
But it does not occur in:
do_something(fn($array, $needle) => $array === $needle);
I think that there's a bug in how we detect the scope of an arrow function which contains a bracket.
https://github.com/sirbrillig/phpcs-variable-analysis/pull/296 should fix this.
Thanks @sirbrillig - that was a quick fix & release!! Working perfectly now.
Turns out the fix was really easy: just stop letting phpcs do its own scope detection for arrow functions. 😁
Consider this code:
$type = in_array_cb($_GET['type'], TYPES, fn(&$array, $needle) => $array[2] === $needle);
The parameter
$needle
is marked as an error: