PhpStorm 2021.2

Aggiunge il supporto preliminare per i generics in PHP e per le enumerazioni in PHP 8.1.
Luglio 30, 2021 - 10:18
Nuova versione


  • Generics for PHP
    • Added preliminary support for generics via the @template annotation. This makes working with collections more straightforward in many cases, because the suggestions will contain elements of the expected type.
    • For factory patterns, you can now use the class-string<T> annotation and you will get better code completion.
      • This preliminary support for generics is not complete and has known limitations.
  • PHP 8.1 Enums - With PhpStorm 2021.2, you can now start using PHP 8.1 enums. The IDE offers code suggestions and validation to protect you from using them incorrectly. An enum in PHP contains a set of cases, can have methods and can be used as a type hint - in all of these cases PhpStorm will provide error highlighting and proper suggestions to save you time.
    • Backed Enums - Enum cases can have scalar equivalents. This is useful if you need to save an enum to a data store. Such enums are known as backed enums. With a quick-fix, you can add a scalar type declaration to a backed enum. Enums also work well with other features, such as conditions and match expressions.
  • Array shapes
    • If there are object-like arrays in your code, you can now define their structure with this PHPDoc annotation: array{key: type, key: type, ...}.
    • PhpStorm provides code completion for such annotated arrays, reducing the time you spend on routine typing and protecting you from mistakes.
    • The support is limited to one-line array shape definitions. For larger structures, it is often better to use real objects and classes.
  • Improved Extract Method Refactoring
    • The Extract method now allows you to split big methods into smaller units and it also eliminates duplicate code.
    • Refactoring duplicate code:
      • PhpStorm has a Duplicated code fragment inspection. It highlights any chunks of code that are very similar – the formatting, variable names and statement order can be different as long as the end result is the same.
      • This inspection highlights the first lines of duplicated fragments. You can now quickly refactor such code by pressing Alt+Enter on the highlighted line and invoking the Extract Method refactoring from the duplicate code quick-fix.
      • PhpStorm can also find duplicates of smaller code fragments in the current scope (method, class, or file) during refactoring. Select a code fragment and then call the refactoring with ⌘⌥M (Cmd+Alt+M / Ctrl+Alt+M). You will see the Review and replace duplicates checkbox at the bottom of the dialog.
    • New smart selector for code fragments - You can also invoke the Extract Method refactoring without selecting any code. In this case, PhpStorm suggests a list of possible code fragments. The suggestions are filtered and contain only segments that make sense to refactor.
    • Improvements to Expand selection - Added the ability to select blocks without curly braces.
  • Inspections and Quick-Fixes
    • Condition can be replaced with `?->` - Replace unnecessary checks for null with the new safe operator from PHP 8. Press Alt+Enter to perform the transformation.
    • Use constant from a class where it is defined - PhpStorm will highlight constants that are accessed via subclass or subinterface instead of the entity where the constant is defined. Replace the name of the entity with the one where the constant is defined using the Alt+Enter quick-fix.
    • Redundant conditions in logical expressions - PhpStorm will now evaluate parts of conditions to identify any redundancies. This can be useful when the checks are not obvious and you can’t tell which ones are redundant just by looking at them.
    • Refactoring Opportunities inspections - Added a new group of inspections in the PHP section of Settings / Preferences | Editor | Inspections. This group includes inspections that can help identify good candidates for refactoring. These inspections are disabled by default, but even in this disabled state, you’ll see an additional gutter icon near the code they detect (instead of having it underlined in the editor).
      • Clicking the gutter icon will invoke the suggested refactoring.
      • These inspections are combinations of various code quality metrics: cyclomatic complexity, nesting depth, number of variables used, total number of lines and many others.
      • You can also find the list of metrics used in the description of each inspection.
  • IDE
    • Run tests before commit - Expanded the list of possible pre-commit actions with the ability to execute tests. When you tick the Run Tests checkbox in the Before Commit section, your IDE will test the applied changes and notify you if anything goes wrong. It is useful to get the code verified before it is in the VCS. You can now also customize the Analyze code and Cleanup options by clicking Choose profile next to them.
    • Actions on save - Added a number of actions that will be initiated by saving the project, including reformatting code and optimizing imports.
    • Unified Show Diff - PhpStorm displays the difference between the initial and changed files in the editor by default, no matter where you’ve invoked the Show Diff action. If tracking changes in a separate window is more convenient to you, just drag the desired file from the editor.
    • Text search in Local History revisions - You can quickly find the necessary text in the Local History revisions by typing the query in the search field in the Local History dialog.
    • GPG signature - This release offers a way to secure your commits by enabling Git commit signing with GPG.
    • Localized UI in Chinese, Japanese, and Korean - Starting with this version, you can enjoy the fully localized PhpStorm UI in Chinese, Korean, and Japanese. Localization is available as a non-bundled language pack plugin, which can be easily installed in your IDE.
  • Web Technologies
    • Rename refactoring for React useState hooks - You will no longer need to waste time on refactoring useState values and functions one by one – PhpStorm can now rename both for you.
    • Auto-import for require() - The IDE can now add missing import statements as you complete CommonJS modules - required imports will be inserted on code completion.
  • Database Tools
    • DDL data source - It is now possible to generate a DDL data source based on a real one. The DDL files are created locally and the new data source is based on them. This way you’ll always be able to regenerate these files and refresh the DDL data source.
    • Completion of fields and operators (MongoDB) - Fields and operators are now available in code completion for MongoDB.
  • Other Enhancements - Here are just a few of the many additional improvements and enhancements in PhpStorm 2021.2:
    • You can now preview HTML and PHP files in a browser using the PhpStorm’s built-in web server. PhpStorm can now automatically reload the opened pages when saving.
    • It is now easier to reorganize tool windows. Hover over the top of the tool window you want to move, then drag and drop it to where you want it.
    • PhpStorm automatically cleans up any directories of caches and logs that were last updated more than 180 days ago. You can also clean up manually via Help | Delete Leftover IDE Directories.
    • New terminal options have been added for setting a cursor shape and for using Option as a meta key.
    • A new Advanced settings page that provides options for fine-tuning PhpStorm has been added in Preferences.
    • Significantly improved the speed of FTP uploads for large collections of files.
    • Added support for levels parameter in dirname().
    • Resolved all outstanding issues with the formatting of PHP code.
Generics for PHP


PHP IDE con refactoring, completamento del codice, analisi del codice on-the-fly e orientamento di produttività di codifica.

PhpStorm è disponibile anche in:

Hai una domanda?

Chatta live con i nostri specialisti di gestione delle licenze di JetBrains ora.