Is there a rename refactoring for PHP in Visual Studio Code? It is the only thing that stops me from fully move from NetBeans to VSC. Renaming is very importat for me (not search/replace).
-
1From what I'm gathering from the "answers" below, this is pushing 5 years old and still doesn't work. This is a basic feature in nearly every IDE, what is VS Code doing? Find/Replace is NOT a suitable replacement for a Refactor->Rename – Mageician May 31 '22 at 17:16
-
1After several years of using VS Code I moved to PhpStorm which has outstanding features for PHP developers (including lots of refactorings). – Dawid Ohia Sep 06 '22 at 08:28
5 Answers
There are
{
"command": "editor.action.changeAll",
"key": "ctrl+f2",
"when": "editorTextFocus && !editorReadonly"
}
and
{
"command": "editor.action.rename",
"key": "f2",
"when": "editorHasRenameProvider && editorTextFocus && !editorReadonly"
}
in the keybindings. F2 appears to work across all files, CTRL-F2 in the current file only.

- 143,421
- 24
- 428
- 436
-
22It's not working as I would expect. When I rename local variable (let say $sum) it should change the name only in the scope where that local variable was defined, not all variables named $sum in the same file or across all files. F2 and CTRL+F2 which you propose work more like find & replace. I am looking for rename refacotring. – Dawid Ohia Oct 16 '17 at 06:04
-
1f2 does not work for php. Just tried it. editorHasRenameProvider == false – Jason Cheng Dec 20 '22 at 22:43
Try this rename symbol instead of the standard find/replace. Rename is bound to F2 for all files, CTRL - F2 for current file, may require installing a php language extension.

- 561
- 9
- 24
-
3Rename symbol doesn't work by default. This feature is in the to-do list of the extension you linked to, it is not implemented yet – Kiruahxh Jan 24 '20 at 17:45
There is an extension called Intelephense extension that provides expected functionality (in paid version as I remember). So I used it for several years in Visual Studio Code and it worked very well.
But I have finally moved to PhpStorm IDE for much more powerful refactoring capabilities and robust PHP support in general.

- 16,129
- 24
- 81
- 95
-
Right, the basic Intelephence does not refactor. And I am unable to buy the paid version, because PayPal fails. And nobody answers to contact e-mail. Then I tried PHP Intellisense, but it says "No refactorings available" as well. So I might revert to PhpStorm after all. – Giorgio Barchiesi Sep 01 '22 at 20:17
-
I got an answer from the contact e-mail, he says the payment error is being worked on. – Giorgio Barchiesi Sep 05 '22 at 07:25
At the time of this posting, the only way I know of to do this is to buy PHP Intelephese Premium. The free version and the other PHP intellisense plugins do not support rename.

- 180
- 2
- 12
Maybe this would be helpfull
ext install marsl.vscode-php-refactoring
Install and use Comand line (Ctrl+P) and activate PHP: Rename local variable

- 11
- 1
-
Doesn't seem to work, i get `PHP Fatal error: Array and string offset access syntax with curly braces is no longer supported` – adxl Jan 08 '22 at 17:54