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.
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.
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:
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.
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.
Null coalescing assignment operator
??= 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.
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.
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.
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:
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.
The Deprecated cast inspection detects the
(real)type-casts and lets you replace them with
The Deprecated implode/join usage inspection detects the usages of the
joinfunction with an array as the first argument and a string as the second argument.