Move Static Member refactoring for PHP in PhpStorm
With the new Move Static Member refactoring in the PhpStorm 7 EAP, we can move static fields and methods to another type. For example when classes contain static methods that are nothing but utility methods, we can move them into a separate type.
The PHPExcel open source project has such a class: PHPExcel_Cell. It contains logic for cells in a spreadsheet as well as several utility methods that convert cell coordinates. Let’s move some of them into a new class: PHPExcel_CellUtils. In the editor we can place the caret on any static method and invoke the Move Static Member refactoring by pressing the F6 key.
After searching the type we want to move these members to, select the methods and fields that should be moved. We can refactor immediately, or use the Preview button to see the changes that will be performed.
PhpStorm will search all references of these static members and make sure they are updated. The IDE will notify us about potential problems as well. Using the Preview button, we can clearly see all occurrences where the methods selected earlier are used and where the Move Static Member refactoring will apply. Click Do Refactor to perform the changes.
Develop with pleasure!
– JetBrains PhpStorm Team
Subscribe to Blog updates
PhpStorm 2024.1 Early Access Program Is Now Open
This EAP build brings support for PHPUnit 11, improvements for the Pest test framework, and more.
PhpStorm 2023.3 Is Now Available
Explore the new features in PhpStorm 2023.3: support for PHP 8.3, the Pest test framework, improvements for Symfony projects and AI Assistant.
PhpStorm 2023.3 RC
PhpStorm 2023.3 Release Candidate bundles the Pest plugin into PhpStorm, so you'll now be able to enjoy it out of the box.