from :
$a = 1;
$b = 2;
$test = function() use($a, $b) {
return $a;
}
to
$a = 1;
$b = 2;
$test = function() use($a) {
return $a;
}
I don't think such rule exist for now.
Note that it would be a risky fixer if it applies the following change:
-$fn = function() use($a, &$b) {
+$fn = function() use($a) {
return $a;
};
because inheriting a variable by reference creates it if it does not exist. So the change would make the variable never created.
another crazy case:
-$fn = function() use($a, $b) {
+$fn = function() use($a) {
$x = "b";
return $$x;
};
don't forget about compact as well;
<?php
$b = 123;
$a = function () use ($b) {
return compact('b');
};
var_dump($a());
(I'm working on this fixer)
Most helpful comment
another crazy case: