#36 Extract to Variable

PhpStorm’s extract to variable feature is an invaluable tool to aid any refactoring task. It allows you to abstract an expression behind a variable, and is smart enough to identify other usages of the expression in your code to be able to replace every other usage with the variable as well.

Press Ctrl+T (Windows/Linux: Ctrl+Shift+Alt+T) to invoke the Refactor This pop up, or choose Refactor | Refactor This from the menus, then select 4. Variable… from the list.

Alternatively, press Cmd+Alt+V/Ctrl+Alt+V to directly invoke the extract to variable action on the symbol under the cursor.

Further Reading

comments powered by Disqus