What’s New in PhpStorm 2021.1

PhpStorm 2021.1 is a major update that introduces the ability to preview for PHP and HTML files in the editor, 20+ new inspections to help prevent bugs, improvements in all subsystems, and pair programming via Code With Me.

PHP

Set the PHP language level in the status bar

Set the PHP language level in the status bar

Set any PHP version for the project without modifying composer.json. This can be helpful, for example, to see how compatible the codebase is with a newer PHP version before actually switching to it.

Locate PHP settings more easily

Locate PHP settings more easily

To make it easier to find and change PHP-related settings, we’ve moved this section to the top level Settings / Preferences | PHP.

Preview PHP and HTML files in the editor

In the Editor, there is a new icon in the top-right corner that opens a tab for previewing files inside of PhpStorm. It works with HTML and PHP files.

Open a PHP file, type your code, and you can immediately see the result alongside it. There is no need to switch to other windows! Any changes in linked CSS and JavaScript files will be reflected in the preview as well.

Preview PHP and HTML files in the editor

PhpStorm uses a local PHP interpreter that is specified in the project settings under Settings/Preferences | PHP. Docker and other remote interpreters are not supported.

You can turn on the preview icon by enabling at least one browser under Preferences | Tools | Web Browsers and checking the For HTML files checkbox.

You can also use the shortcut Alt+F2 to open a preview tab.

Use table prefixes in SQL queries

Many content management systems and frameworks allow you to specify a table prefix, which is useful when using the same database for multiple applications.

Use table prefixes in SQL queries

In previous versions, PhpStorm would lose database integration in such cases because SQL queries contained markers for prefixes.

Now it is possible to specify prefixes via the .phpstorm.meta.php file. Learn more about meta files and how to specify SQL prefixes in the help article.

Inspections and quick-fixes

Boolean expression can be simplified

Boolean expression can be simplified

If a boolean expression contains true or false literals, PhpStorm can help simplify it. Use an Alt+Enter quick fix to remove redundancies and improve readability.

Strict comparison of operands with incompatible types

Strict comparison of operands with incompatible types

The === operator for strict comparison will always result in false if one operand type is not the same as the other.

PhpStorm will highlight such cases, as they can potentially be a source of bugs. PhpStorm takes into account all type-inferred information, and will help you find issues in less obvious cases.

PHP 8: Replace assignment in the function call with named argument

PHP 8: Replace assignment in the function call with named argument

It used to be common practice to add a variable assignment in a function call to mimic a parameter name.

With PHP 8, use Alt+Enter to replace the assignment with a real named argument.

Replace `isset` with coalesce

Replace `isset` with coalesce

This code snippet isset($a) ? $a : $b; is exactly the same as $a ?? $b, so PhpStorm will suggest an Alt+Enter quick-fix to replace it.

Simplify `if` blocks with the common body

Simplify `if` blocks with the common body

Some if or else blocks may become redundant after changes that make their bodies the same. PhpStorm will offer either to extract common parts or to merge blocks.

Invert `if` statement

Invert `if` statement

Press Alt-Enter on any if and choose Invert `if` statement from the menu. This will change the condition to its opposite and make the necessary code adjustments to preserve the logic. If you are a fan of the early return practice, this action will help you refactor your code.

Unnecessary leading ‘\’ in ‘use’ statement

Unnecessary leading ‘\’ in ‘use’ statement

In some cases, the leading backslash is redundant for namespaces. PhpStorm helps determine where it can be removed.

`foreach` variable overwrites already defined variable

`foreach` variable overwrites already defined variables

Variables for key and value in a foreach loop can clash with the names of other variables or parameters. PhpStorm highlights all of the places where errors could occur.

Unnecessary curly braces syntax for variables

Unnecessary curly braces syntax for variables

PhpStorm highlights when the curly braces in the context of string interpolation are redundant and can be safely removed to make the code cleaner.

Change parameter type based on a default value

Change parameter type based on a default value

If the declared type does not match the type of a value, you can quickly update the type using Alt+Enter. Or with PHP 8, PhpStorm will offer to use a union type.

Replace `isset` with `!== null`

Replace `isset` with `!== null`

Using the isset() function is only effective for arrays and variables. In all other cases, it makes sense to verify whether the operand is not null. Use Alt+Enter to replace isset() checks with null checks.

Highlight unsafe http:// links

PhpStorm highlights http:// protocol usages in strings and offers an Alt-Enter quick-fix to change them to https://. You can also add URLs to the ignore list with a quick-fix.

Suspicious name combination

Suspicious name combination

PhpStorm highlights some typical misusages of parameter names or return values, for example, $needle and $haystack or $x and $y. This could be a potential bug or at least very confusing for those who read the code.

Configure pre-commit inspections

Configure pre-commit inspections

You can now choose a code inspection profile before committing changes to the VCS. Click the gear icon to show commit options, then tick the Analyze code checkbox, click Configure, and choose the desired profile. Profiles can be created in Preferences/Settings | Editor | Inspections.

Other

Synthetic scope for better refactoring

Synthetic scope for better refactoring

In PHP, loop constructs like foreach, for, while, and catch blocks do not have isolated scopes. This can be inconvenient if you want to rename a variable only inside a block.

In PhpStorm 2021.1, we have introduced a synthetic scope for such blocks, so the rename refactoring (Shift+F6) will be more intuitive.

Better automatic language injection

Better automatic language injection

PhpStorm 2021.1 analyzes how variables are used and injects language references automatically.

For example, if a variable is used in a preg_* function, PhpStorm knows it’s a pattern and highlights RegExp.

Extensions in `suggest` section of composer.json

Extensions in `suggest` section of composer.json

PhpStorm now considers extensions in both require and suggest sections.

PhpStorm will warn you when an extension is registered in composer.json as suggested but is used without checks, like extension_loaded() or function_exists(). You can use a quick-fix to move extensions to require/require-dev.

Notable fixes

In this release, our main focus was stability and quality. In total, we fixed 2246 issues submitted to our issue tracker by users and JetBrains team members. Here are just a few of the most interesting ones:

  • Debugging WSL 2 projects in Docker is now possible.
  • Quality tools now properly resolve paths with docker-compose in exec mode.
  • Large files (more than 5k lines) are handled correctly.
  • We’ve significantly improved performance in projects with many aliases.

Code With Me

Collaborative development via Code With Me

Code With Me is a JetBrains tool for collaborative development and pair programming. We initially introduced it in PhpStorm 2020.3, and this release delivers a number of significant improvements.

Set the needed level of access to your project and share the link with your guests. Peers do not even need to have their own IDEs installed to collaborate, and the platform features embedded audio and video calls, along with chat messaging.

For businesses that require extra security, Code With Me on-premises can be installed and securely run on a company’s own private network.

HTTP Client

Support for SSL

Support for SSL

You can now define SSL settings in the HTTP client by clicking Add environment file and selecting Private. The IDE will automatically create a file where you can add your SSL configurations: clientCertificate, hasCertificatePassphrase, clientCertificateKey, verifyHostCertificate.

UI improvements

UI improvements

There is a new eye icon that contains options for the way the body is displayed. You can switch modes between Text / JSON / HTML / XML, you can enable line numbers, and there is a new button to quickly Copy Response Body to Clipboard.

IDE

Maximize tabs in split view

Maximize tabs in split view

Split the editor by dragging a tab to the corners of the IDE window. Then double-click the tab to maximize the editor area for it. Double-click it again to restore it to its original size.

JSONPath support

JSONPath support

Use the JSONPath query language to search through JSON documents. New actions are available under Edit | Find | Evaluate JSONPath.

JSON Lines format support

JSON Lines format support

PhpStorm now supports the newline-delimited JSON Lines format used for working with structured data and logs. The IDE will recognize .jsonl, .jslines, .ldjson, and .ndjson file types.

Typography settings

Typography settings

It is now possible to adjust font variations and a fallback font. Find the new options under Typography Settings in Settings / Preferences | Editor | Fonts.

Web Technologies

All the new features and improvements from WebStorm 2021.1 are also available in PhpStorm 2021.1, either out of the box or with free plugins from the Plugin Marketplace.

Improved support for Stylelint

Improved support for Stylelint

You can now fix problems in CSS with Stylelint in just a few clicks. Hover over a problem in your file or place the caret on it and press Alt+Enter, then select Stylelint: Fix current file.

Additionally, you can now specify a path to the configuration file under Settings / Preferences | Languages & Frameworks | Style Sheets | Stylelint.

Check the specificity of your selectors

Check the specificity of your selectors

When working with style sheets, you can now check the specificity of your selectors – just hover over a selector that you want to check. Alternatively, focus on a selector and press F1/Ctrl+Q to see this information in the Documentation popup.

GitHub pull request improvements

To create a new pull request, click on the + icon or go to Git | GitHub | Create Pull Request.

GitHub pull request improvements

The new dialog includes everything you might need:

  • Select base and head branches from a list that includes all the branches available.
  • Review changed files in the Files tab.
  • Edit PR title and description, appoint reviewers and assignees, and add labels.
  • Create draft pull requests.

Database Tools

Take a look at What’s new in DataGrip 2021.1 – all these features are available in PhpStorm, too. Here are just a couple of them.

UI for grants

UI for grants

The Modify user window, which you can invoke on a user in the database explorer with Cmd/Ctrl+F6, now has a UI for adding grants to objects.

This is available for PostgreSQL, Redshift, Greenplum, MySQL, MariaDB, DB2, SQL Server, and Sybase.

Context live templates

Context live templates

This is our solution for anyone wanting to generate simple statements straight from the database explorer. When you right-click on an object in the explorer, the list that appears will contain special live template items.

Learn more about how to create your own context live templates.