PhpStorm 2021.3 EAP #6

To make PhpStorm fully ready for PHP 8.1, we recently introduced support for the `new` operator in initializers, first-class callables, and some major deprecations in the language.

There is also a new VCS action: Push All up to Here.

Let’s look into these in more detail.

The Early Access Program is coming to a close, and we are now focusing on stabilizing and polishing PhpStorm for release. This is a good time to report any lingering issues that you’ve encountered, as there is still time to fix them before the release.

Download PhpStorm 2021.3 EAP

PHP 8.1

Check out the previous posts to see how other PHP 8.1 language updates will be supported in PhpStorm:

Enums (available since PhpStorm 2021.2)
Readonly properties
Pure intersection types
Final class constants
The `never` return type

Now let’s get to the rest.

`new` operator in initializers

In PHP 8.1, objects can be used as default parameter values, static variables, and global constants, as well as in attribute arguments.

A cool side effect is that nested attributes are now possible with this change.

But you can’t use the new operator with properties. Or rather, it will be possible to use it via constructor property promotion only, but those are actually parameter arguments, not default property values. See for yourself: 3v4l.org/r9iv4.

In addition, you cannot use the new operator with class constants because of problems with the initialization order.

PhpStorm validates all the cases to help you use these new language features:

First-class callables

In PHP 8.1 it will be possible to get a reference to any function – this is called first-class callable syntax.

It was like this:
$fn = Closure::fromCallable(’strlen‘);

Now you will be able to do the following instead:
$fn = strlen(…);

The advantage is that the new syntax is accessible to static analysis, and it respects the scope at the point where the callable is created.

In PhpStorm, convert fromCallable calls to the new syntax by pressing Alt+Enter and choosing a quick-fix from the dropdown list:

Deprecations

PHP has been known for its quirky behavior in some cases. Every PHP release cleans them up, and 8.1 is no exception as it deprecates a lot of legacy things.

PhpStorm will help you find deprecated code in your projects and make the upgrade process easier.

Let’s take a closer look at some of the significant deprecations.

Deprecated usage of Serializable interfaces

Instead of broken Serializable interfaces, you’re recommended to use __serialize() and __unserialize() magic methods, which were introduced in PHP 7.4.

In PHP 8.1 you can still use Serializable, but only if the implementing class has __serialize() and __unserialize() as well.

PhpStorm will highlight incorrect code for you and offer a quick-fix to add the magic methods to a class:

Restricted GLOBALS usage

First of all, usage of the GLOBALS superglobal variable will be restricted to disallow the problematic cases, while allowing most code to continue working as-is.

Forbid autovivification on false values

Automatic conversion of false values to array will throw a deprecation notice in PHP 8.1.

The point is to reduce possible bugs when using functions that may return an array on success and false on error.

To learn more about all deprecations see the Migration Guide.

VCS: New ‘Push All up to Here’ action

Sometimes, you may have several commits that are ready to be shipped while others are still work in progress. In such cases, you may want to push only the ones you are sure about.

In this release, PhpStorm will let you push commits up to the one you have selected in the Log tab of the Git tool window. To do so, select the necessary commit, right-click it to open the context menu, and select the new Push All up to Here action.

The full list of changes in this build is available in the release notes.

Important! PhpStorm EAP builds are not fully tested and may be unstable.
You can install an EAP build side by side with a stable PhpStorm version to try out the latest features.
EAP builds are free to use but expire 30 days after the build date.

Please report any problems you find to our issue tracker or by commenting on this post.

Your JetBrains PhpStorm team
The Drive to Develop

The PhpStorm Blog : The Lightning-Smart IDE for PHP Programming | JetBrains Blog
Read More

Generated by Feedzy