PhpStorm 2019.2 Released: PHP 7.4 Typed Properties, Locate Duplicates, RegExps for PHP, EditorConfig, Shell Scripts, and More
PhpStorm 2019.2 is now available!
Along with performance and stability improvements, this major release brings new features such as support for PHP 7.4 Typed Properties, locating duplicated code on the fly, highlighting and checks for RegExps in PHP, out-of-the-box support for EditorConfig, Shell Scripts, syntax highlighting for over 20 programming languages, and loads more!
Explore the top new features and download PhpStorm 2019.2 on our website.
In this blog post, we’ll go through all the significant changes in detail. It’s a combination of all the EAP blog posts that we’ve been publishing here over the past several months. Fasten your seat belts and let’s go!
PHP 7.4 Typed Properties
PHP 7.4 is going to be the most outstanding and feature-rich release since PHP 7.0! Check out all the accepted features.
The most anticipated feature is Typed Properties, and PhpStorm 2019.2 already fully supports it! This includes highlighting, type inference, and checks.
To quickly add a type declaration, press Alt+Enter over a property without a type, and then choose Add declared type for the field. PhpStorm will detect the type automatically based on the PHPDoc, default value, or argument type declaration if the value is injected via constructor.
??= (null coalesce assign) operator
The new shorthand assignment operator with a check for null is quite handy, especially when you have some long variables or statements.
The syntax support and highlighting in PhpStorm goes without saying, but PhpStorm also comes with a quick-fix Alt+Enter to reduce redundancy when the ??
operator occurs:
Spread operator in arrays
PHP has already supported argument unpacking (a.k.a. spread operator, a.k.a. ...
) since v5.6. In this upcoming version, PHP will bring the operator into array expressions, which PhpStorm 2019.2 supports as well:
Behind the scenes, PhpStorm also checks for correct usage of the operator and makes sure you are unpacking only arrays and Traversables and not doing anything that is not supported by the PHP interpreter:
In the next PhpStorm 2019.3 release, we expect all the PHP 7.4 features to be supported, such as arrow functions, numeric literals seprator, covariant returns and contravariant parameters, and more.
Regular Expression Injections
Previously in PhpStorm, regular expression patterns in PHP code were not highlighted by default and they appeared just as plain text.
Now PhpStorm 2019.2 comes with full RegExps support for PHP! This means that whenever your code uses preg_*
functions, the pattern will be highlighted and verified for correctness automatically.
Moreover, you can now test your patterns right in the IDE! Move the caret over the pattern and press Alt+Enter to get the quick action Check RegExp.
Duplicates detection on the fly
It’s been a while since we added search for duplicates, accessible via Code → Locate Duplicates. It can help you eliminate duplicates and make your code more concise and stable. If you’ve never used it, you definitely should because it’s truly surprising how many duplicates an average codebase usually contains!
This PhpStorm release takes the duplicate analysis to an entirely new level, by allowing you to spot them on the fly. Now, if you stumble upon an existing duplicate, or somehow create one, either by writing new code or pasting a piece of code, you will know about it instantly.
The analysis comes with an intention action that lets you navigate to the duplicates or display them in a tool window:
These are good candidates for Extract refactoring, by the way.
The new inspection is called Duplicated code fragment and it is enabled by default. You can configure the duplicate threshold under Preferences | Editor | Inspections | General | Duplicated code fragment → PHP. Other relevant settings are found under Preferences | Editor | Duplicates.
Support for PHPT test files
Looking to contribute to the PHP interpreter source and join the PHP Internals core team? That could be a tough task if you don’t know C all that well. The best way to start contributing to any open source project is to write documentation or add tests! Fortunately, for the latter, you only need to know PHP. Tests for PHP are written in special .phpt files, which are basically a set of PHP scripts with additional information divided into several sections.
Well, PhpStorm 2019.2 comes with support for .phpt files!
- Highlighting for sections and scripts
- PHP and INI languages auto-inject to the corresponding sections
- Completion of section names
- Jump to files referenced in EXTERNAL sections
Find more useful information about writing tests for PHP source on PHP TestFest Tutorials, PHP Internals Book, and qa.php.net.
Composer via any remote PHP interpreter
Just recently, in PhpStorm 2019.1.2, we added support for running Composer via a Docker image. Building on that, we can now confirm that PhpStorm 2019.2 is able to run Composer via any remote interpreter configured in your IDE. It could be Docker, Docker-compose, Vagrant, remote server via SSH, or anything else.
To check out this feature, go to Preferences | Languages & Frameworks | PHP | Composer and select Remote Interpreter.
Choose any interpreter from the dropdown or add a new one!
Intentions & Quick-fixes
Convert a single line list to multiline, and back
According to PSR-2, lines longer than 80 characters should be split into multiple subsequent lines of no more than 80 characters each. So if you have a long array or function argument/parameter list written on one, you can press Alt+Enter over it and choose the action Split comma-separated values into multiple lines:
The opposite action to combine items into one line is also available and called Join comma-separated values into a single line.
This works anywhere in PHP for arrays, argument lists, and parameter lists.
By the way, you may see you need to fix your code style settings. Select the region in which you don’t like the code style, press Alt+Enter, and choose Adjust code style settings. For your ease, PhpStorm will offer to update only those settings that affect the selected lines:
Intention and inspections for Switch statement
First, it is now possible to add branches faster by copying existing ones and then modifying them. Press Alt+Enter on the body-less case statement and choose Copy ‘switch’ branch.
Don’t forget to modify a copied one, because PhpStorm will warn you if a switch block has a duplicated branch, i.e. the same body, which can either be redundant or written by mistake:
Also, in PhpStorm 2019.2, if you have a switch statement without a default branch in your code, you can quick-fix this with Alt+Enter as well.
Additions to the string juggling toolbox
PhpStorm can help you with routine string manipulations. Whenever you need to split a string, change quotes, convert interpolation to sprintf
call, or concatenation to interpolation – just press Alt+Enter on a string and choose the appropriate action from the list.
In PhpStorm 2019.2, we’re extending this list with a couple more neat additions.
Let’s say you have a long sprintf
expression, but you need to replace a substring and make it a parameter. Simply select it, press Alt+Enter, and PhpStorm will choose the correct place for a parameter for you:
This also works when you need to extract a part of a string and concatenate:
Other PHP-related updates
Method Breakpoints via the gutter
As you debug, sometimes you want to find out whether the execution flow goes into a certain function, i.e. whether the function did or did not run. To do this, you had to find the first executable line in a function body and put a breakpoint on it.
PhpStorm 2019.2 supports method breakpoints, so all you need to do is set a breakpoint on the function declaration line and instead of a round icon, you’ll see a rhombus.
Structural Search Preview
Structural Search is a powerful tool that lets you search for specific code patterns not only by text but also by defining type constraints. Go to the menu Edit → Find → Search Structurally… to try it.
The problem with structural search is that it can be tricky to create a good search pattern. PhpStorm 2019.2 comes with a welcome change – now the IDE instantly highlights the found occurrences of your structural search in the editor. You don’t have to run a modified pattern over and over anymore as you experiment with your search pattern.
HTTP Client
Support for cURL format
Most web development and documentation tools nowadays provide a “Copy as cURL” command so that you can “replay” the request and see how it works.
Now you can work on such requests in PhpStorm. Just create a new .http file or a HTTP-request scratch file with Cmd+Shift+N, and then paste a cURL request string. It will be automatically converted to a full request.
HTTP client keeps all cookies
Let’s say you’ve made one request to authenticate on the service, and in the subsequent requests you would like to call some endpoints that require additional permissions. Previously, you would lose the authentication cookie from the first response. Now, this is fixed! PhpStorm saves all the cookies for you and transfers them in the next request.
If you don’t want cookies to be saved from a specific request, add a special tag, @no-cookie-jar
.
Version Control
A new commit flow with no modal dialog
Let’s say you have made a bunch of changes in files in different folders in your project hierarchy. To commit them, you go to the Local Changes tab in the Version Control tool window. You select the files and then see another popup to type in a commit message. At this point, you’re blocked by the popup and cannot see your project.
PhpStorm 2019.2 lets you commit directly from the Local Changes.
Now while working on a commit, you can browse through the source code, view the history for a specific file, view the diff for the file in the same area as the commit, and use the other features of the IDE. Previously, all these actions were impossible because the modal commit dialog blocked off all the other IDE functionality.
To enable this feature, select the “Commit from the Local Changes without showing a dialog” checkbox under Preferences | Version Control | Commit Dialog.
Reminder to commit related files
When you’re forming a commit, PhpStorm 2019.2 may suggest that you include the files you typically modify, together with the files you’re currently committing.
Improvements for working with .gitignore
PhpStorm supports .gitignore
and highlights ignored files and folders listed in the Project view.
Now, we’re making it a bit easier to add unversioned files to .gitignore
. To do this in the Version Control tool window, right-click on a file in the Unversioned files group and select Add to .gitignore.
Code completion is available for file and folder names in your .gitignore
file. Cmd+click on the name to jump to it in the Project view.
Hide author, data, or hash from Log columns
Show Diff with Working Tree action
To view the difference between the current and selected branches, choose a new Show Diff with Working Tree action in the Git Branches popup.
History for directories from the Project View
To see the history of directories, select several folders in Project View and see all changes in any of these folders by choosing Git | Show History from the context menu.
Docker
We’ve moved Docker to the brand new Services tool window. The goal of this tool window is to provide a single place to view all the connections and running processes. Currently, by default in PhpStorm, it includes Docker and Database connections. You can also add Run/Debug configurations to the Services tool window under Run | Edit Configurations… | Templates in the Configurations available in Services section.
You can view all the service types as nodes, or you can alter the view to see them as tabs. Use the Show in New tab action from the toolbar, or simply drag and drop the needed node onto the edge of the Services tool window.
Browser for Docker container file system
It is now possible to view the file system of the running Docker container. The file system will be displayed in the newly added Files tab.
Editor
Code completion for mistyped keywords and names
As you type, it can often happen that you accidentally mix up some characters. For example, you’ll type funtcion
or fnction
instead of function. Now, code completion can understand this kind of typo and will still suggest the most relevant option to you.
This works in all the supported languages and for all symbols – keywords, classes, functions, members, and so on.
The ‘Move Caret to Next Word’ action provides options
The Move Caret to Next Word action now allows you to choose where you want to place the caret: at the end of the current word or at the beginning of the next word. Pick the behavior which best suits you in the Caret Movement area in Preferences | Editor | General.
Tab now takes you outside the closing bracket or quote
Another feature to help you type faster is now available out of the box: the Tab key navigates you to outside of the closing brackets or quotes. To disable this option, go to Preferences | Editor | General | Smart Keys and deselect the Jump outside closing bracket/quote with Tab when typing checkbox.
Selected code gets wrapped in quotes or braces automatically
Another super-handy feature that has been around for a while is now also enabled by default: when you type a brace or a quote, PhpStorm automatically wraps the selected code in braces or quotes.
If you don’t like this feature as much as we do, go to Preferences | Editor | General | Smart Keys and uncheck Surround selection on typing quote or brace.
macOS now has a new default keymap
We’ve changed the default keymap for macOS from Mac OS X to macOS 10.5+. We’ve also renamed the keymaps: Mac OS X 10.5 is now called Default for macOS, and the outdated Mac OS X is now IntelliJ IDEA Classic.
Syntax highlighting for over 20 languages
Do you have some files in your project in a language other than PHP? In PhpStorm 2019.2, we’ve added syntax highlighting for over 20 different programming languages, including Python, Ruby, and Go. It just works – no additional configuration required.
With this change, we want to improve the experience of our users who occasionally have to look through code written in languages that are not fully supported in PhpStorm. But PhpStorm is still primarily an IDE for PHP and Web, so we don’t plan to extend the support for these other languages beyond syntax highlighting.
Syntax highlighting for these languages is built using TextMate grammars, and PhpStorm bundles a collection of grammar files for different languages. See the full list of supported languages under Preferences | Editor | TextMate Bundles.
Shell Scripts
PhpStorm 2019.2 provides rich editing support for shell scripts, including word and path completion, rename refactorings, code generation Cmd+N, and a number of live templates Cmd+J.
PhpStorm also includes integration with several external tools to enhance the shell script support even further.
For detecting possible errors in your script, the IDE will prompt you to install the inspection tool named Shellcheck, which can detect a ton of issues and provide quick-fixes for them.
PhpStorm 2019.2 also integrates with the external formatter engine known as mvdan/sh. When you invoke the Reformat Code action for the first time, the IDE will suggest installing this tool, and once that’s done PhpStorm will properly format your shell script.
And last but not least, there’s integration with the Explainshell website. You can select a command in the editor and press Alt+Enter on it. The IDE will then take you to Explainshell where you’ll find a detailed explanation of the selected command.
EditorConfig
Putting an .editorconfig file in the root of your project helps maintain consistent coding styles for multiple developers working on it across various editors and IDEs.
Previously, you had to make sure that all the developers in your team installed the EditorConfig plugin in PhpStorm, but in 2019.2 it comes bundled and works with no additional steps.
You can set different code style settings for each scope in your project. All you need to do is place the .editorconfig
file in the root directory of a folder. You can have as many .editorconfig
files as you need in a single project.
PhpStorm can manage PhpStorm-specific options in the same file as well!
The new IDE-specific options cover most of the code style settings, which before could be configured only via the UI. These options have the prefix ij_
to distinguish them from the standard EditorConfig properties.
Also, you can now create the EditorConfig file from the Project View. Select a directory, call up the context menu, and choose New | EditorConfig. The IDE will provide you with a choice to create a EditorConfig file with standard and/or PhpStorm-specific properties. In this dialog, you can also choose the language options you would like to include in the EditorConfig File.
Appearance
More info in Project View
We have added the option to display more info about the files in the Project View. Toggle In-place Descriptions under the View menu to get a preview of the file size, and the date and time modifications.
New look for inspection tooltip
The inspection tooltip now not only displays the problem description but also instantly provides you with the first available fix. To apply the first suggested fix, use Alt+Shift+Enter or the standard Alt+Enter to see all the available quick-fixes.
Updated UI on Windows
PhpStorm has a new modern borderless look on Windows 10.
Web Technologies
- A new Propagate to destructuring intention can replace an extra variable, if it is possible, with another destructuring.
- When you rename a symbol in a JavaScript or TypeScript file, the IDE now groups together dynamic usages and, by default, excludes them from the refactoring.
- Multiple improvements for Vue.js support.
See all the changes made by our colleagues from the WebStorm team on the What’s new in WebStorm 2019.2 page. Everything mentioned there is incorporated to PhpStorm 2019.2 as well.
Database Tools
- Full-text search allows you to search through the data sources or groups of data sources for data in an unknown location.
- Filtering by data source in search and navigation is now possible.
PhpStorm includes all the features of DataGrip out of the box, so there are many new things to discover in DB tools. Stay tuned for a detailed overview of the DataGrip 2019.2 release.
A full list of all the changes is available in the really long release notes.
JetBrains PhpStorm Team
The Drive to Develop