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](https://resources.jetbrains.com/help/img/idea/2022.1/ps_adding_typed_properties.png)
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 Nested ternary operator usage](https://resources.jetbrains.com/help/img/idea/2022.1/ps_nested_ternaries.png)
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](https://resources.jetbrains.com/help/img/idea/2022.1/ps_add_number_separators.png)
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 Using covariant and contravariant types](https://resources.jetbrains.com/help/img/idea/2022.1/ps_covariant_contravariant.png)
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](https://resources.jetbrains.com/help/img/idea/2022.1/ps_null_coalescing_assign.png)
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 Spread operator in arrays inspections](https://resources.jetbrains.com/help/img/idea/2022.1/ps_spread_operator_in_arrays_inspections.png)
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 Outer scope variables completion inside a closure](https://resources.jetbrains.com/help/img/idea/2022.1/ps_closure_outer_scope_var.png)
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](https://resources.jetbrains.com/help/img/idea/2022.1/ps_convert_closure_to_arrow_function.png)
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.
The Deprecated cast inspection detects the
(real)
type-casts and lets you replace them with(float)
casts.The Deprecated implode/join usage inspection detects the usages of the
implode
orjoin
function with an array as the first argument and a string as the second argument.The Curly brace access syntax usage inspection detects the deprecated usages of curly braces for accessing array elements and string offsets.
The Short open tag usage inspection detects the usages of short open tags, which are deprecated in PHP 7.4, and are planned for removal in PHP 8.0. See the RFC for details.