1.2.1029. Redefined Default¶
Classes allows properties to be set with a default value. When those properties get, unconditionally, another value at constructor time, then one of the default value are useless. One of those definition should go : it is better to define properties outside the constructor.
<?php
class foo {
public $redefined = 1;
public function __construct( ) {
$this->redefined = 2;
}
}
?>
1.2.1029.1. Connex PHP features¶
1.2.1029.1.1. Suggestions¶
Move the default assignation to the property definition
Drop the reassignation in the constructor
1.2.1029.1.2. Specs¶
Short name |
Classes/RedefinedDefault |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Examples |
|
Available in |