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
Thanks, we've got you!
PhpStorm 2023.2 Beta
In this build, we’ve added new inspections for PHP assertions and revised the integration with third-party quality tools.
PhpStorm 2023.2 EAP #6
This build brings improvements for generating PHPDocs, support for Laravel Pint, a single point of access to all PHP framework plugins, and much more!
AI Features in PhpStorm: PhpStorm 2023.2 EAP #5
The next EAP build for PhpStorm 2023.2 is now available, and it’s an exciting one! It is the first build to include features leveraging the enormous potential of generative AI and large language models (LLMs). Our Early Access Program (EAP) allows you to try new features from the upcoming PhpStor…
PhpStorm 2023.2 EAP #4
This build includes a bunch of usability improvements, such as abilities to pin Run configurations and sort files by modification time in the Project view. The EAP allows you to try new features from the upcoming PhpStorm version, 2023.2. EAP builds are free to use and you can install them side b…