PhpStorm 2020.3 Help

PHP 7.4

PHP 7.4 brings new features, syntax additions, and bugfixes. For details on migrating your code, refer to the Migrating from PHP 7.3.x to PHP 7.4.x guide.

Typed properties

With typed properties support, you can declare type hints to the class variables and properties. PhpStorm highlights and resolves typed properties, and displays type violations if any. You can use the Add declared type intention action Alt+Enter letting you add a type hint on the fly based on the PHPDoc, default value, or argument type declaration.

Adding typed properties

Nested ternary operator

PHP 7.4 deprecates left associativity for the ? ternary operator. You should either not use nested ternaries at all, or if you have to, provide parentheses to explicitly declare the computations order. The Nested ternary operator usage inspection will highlight deprecated expressions and provide you with a quick-fix to clarify the behavior:

Nested ternary operator usage

Numeric literal separator

When working with long numbers, you can place underscore separators anywhere in a numeric literal to visually format it and thus improve code readability. To do this, use the Add number separators intention action Alt+Enter.

Adding numeric literal separators

Covariant Returns and Contravariant Parameters

When you work with a method inherited from a parent class, you can define less specific parameter types and more specific return types. That is, a parameter type can be substituted with one of its supertypes, while a return type can be substituted by its subtype.

Using covariant and contravariant types

Null coalescing assignment operator

The ??= null coalescing assignment operator lets you combine the null coalescing and assignment operations into one. This way, you can shorten long code constructs. PhpStorm detects the usages of the ?? operator and provides a quick-fix to reduce redundancy.

Null coalescing assignment operator

Spread operator in array expressions

In PHP 7.4, you can use the ... spread operator inside array expressions. Earlier, it was only available inside functions' arguments lists. The Invalid type of unpacked argument inspection checks for correct usage of the operator and makes sure you are unpacking only arrays and traversables.

Spread operator in arrays inspections

Arrow functions

When writing simple one-line lambda functions in PHP 7.4, you can use the short arrow syntax: fn(parameter_list) => expr. Short arrow functions introduce automatic by-value binding of variables from the outer scope. PhpStorm provides completion for them as well as resolves declarations.

Outer scope variables completion inside a closure

To convert a lambda function from the old syntax to the new short one, you can use the corresponding Convert closure to arrow function intention action:

Converting a closure to an arrow function

Deprecations

PHP 7.4 deprecates several language constructs. You can view the full list of deprecations here. PhpStorm highlights such deprecated usages and provides quick-fixes for them.

Last modified: 08 March 2021