1.2.1385. Useless Assignation Of Promoted Property¶
Promoted properties save the assignation of constructor argument to the property. It is useless to do it with that syntax, and in the constructor too.
<?php
class x {
private $b;
function __construct(private $a,
$b,
) {
// This is already done with the promoted property
$this->a = $a;
// This is the traditional way (up to PHP 8.0)
$this->b = $b;
}
}
?>
1.2.1385.1. Connex PHP features¶
1.2.1385.1.1. Suggestions¶
Remove the assignation in the constructor
1.2.1385.1.2. Specs¶
Short name |
Classes/UselessAssignationOfPromotedProperty |
Rulesets |
|
Exakat since |
2.5.0 |
PHP Version |
With PHP 8.0 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |