Refactor within scope

If I have this loop:

foreach($variables as $variable){
   echo $variable;
}

I highlight this block and press Ctrl+D and end up with this:

foreach($variables as $variable){
   echo $variable;
}

foreach($variables as $variable){
   echo $variable;
}



Then I click on the second "$variable" and rename it (Shift+F6) it also renames the variable in the previous loop.

Is there plans for "rename within scope" ? So it would only rename the variable within the foreach() loop (and possibly anything after the loop) (and then possibly everything up to and including any unset()'s of that variable after the loop) ?

Thanks! :)
Dave
7 comments
Comment actions Permalink

Actually, $variable is local to the foreach....so in my opinion that is a bug, or at least inconsistent. Refactor already does scope (functions, for example) and this should fall into that category.

Alexey?

0
Comment actions Permalink

Actually, $variable is local to the foreach


Could $variable also be considered local to anything after foreach, ie: highlighted variables below:

foreach($variables as $variable){
   echo $variable;
}
foreach($variables as $variable){  // cursor is positioned on this $variable
   echo $variable;
}
$variable ++;
echo $variable;
unset($variable);
$variable = 1;  // unrelated to previous $variable
echo $variable;

0
Comment actions Permalink

Yes, I would think it would have to (since that is what actually happens.)

0
Comment actions Permalink

Are there any news about it? Refactoring variables still works for entire function / method. From time to time I need to change names manually within loop or if statement because of it.

0
Comment actions Permalink

Multiple carets should help in such cases -- does the job for me.

0
Comment actions Permalink

Sometimes it helps as well as find and replace. However for larger blocks of code, refactoring within selection or inner statement will do this job in a second without any mistake.

0

Please sign in to leave a comment.