Hello guys,
We are working hard on new features for PhpStorm 2.1, and the ‘Extract Function/Method’ refactoring for PHP is one of them. This feature has been available since the first PhpStorm 2.1 EAP(106.444), and we are looking forward for your feedback.
The main point of the refactoring is to convert a part of a larger function/method into a new function/method. This might be useful if you need to make your code easier to understand or reuse a specific code fragment.
Let’s try to put this refactoring into practice.
Select a code fragment (Picture 1a) or an expression (Picture. 1b).
Picture 1a: Select a code fragment
Picture 1b: Select an expression
Invoke the refactoring from the menu ‘Refactor -> Extract Method‘ or using a hotkey. The default hotkey is Ctrl+Alt+M for Windows/Linux and Cmd+Opt+M for Mac.
Depending on the context of the selected code fragment, ‘Extract method’ (the code fragment is inside a method) (Picture 2b) or ‘Extract Function’(the code fragment is inside a function or script) (Picture 2a).
Picture 2a: ‘Extract Function’ dialog
Picture 2b: ‘Extract Method’ dialog
Enter the name of the new function/method. Press OK.
Picture 3a: The code fragment is replaced with a function call statement
Picture 3b: The expression is replaced with a method call expression
Picture 4a: Definition of the extracted function
Picture 4b: Definition of the extracted method
Develop with pleasure!
For up-to-date information please follow to corresponding WebStorm blog or PhpStorm blog.








It’s just toys. It can be done easy without any ‘new refactoring’, just copy+paste (and will be less errors). Please, create ‘Extract Interface’ refactoring, it will be much more useful.
http://youtrack.jetbrains.net/issue/WI-5093
This one is the the most useful refactoring type for me (after rename, of course). Tried it in 107.21 and it worked flawlessly.
I once tweeted: PHPStorm is great, now all I need is Extract Method. Well, you have provided! Great work.
Keep this up. Can’t wait to renew my license for another year.
Lol, my comment is being hidden.
Well, I can’t understand why this method looks ‘great’ for you, but I respect your opinion – maybe it’s just rare operation for me.
But, I can’t believe that nobody cares about interfaces. It’s so important part of OOP… And forgotten features for interfaces looks weird.
Hi, Oz.
No, it just was “under moderation”
Don’t know why our spam-filter concerned that your message requires additional attention from moderators. As regards development plans our developers will answer better than I.
Alexey Korsun,
marketing manager
Hi, Alexey, thank you.
This is great and will save countless development hours. Perhaps OZ above is one of the lucky few who work mostly on new projects!
@OZ
18 votes for ‘Extract Method’(WI-2779) versus 3 votes for ‘Extract Interface’(WI-5093);) ‘Extract Interface’ refactoring is great one, but we need to listen our community.
Will this also work for Javascript? If not, is it planned?
Now that looks *VERY* promising! Can’t wait till to try it out.
@John
Yes, the refactoring works for JavaScript also.
@Alex
Your previous comment about the refactoring was the reason of big improvements. Thank you for constructive feedback!
Nils Luxton, this refactoring very useful for old code exactly, to replace type hinting and avoid high coupling.