1.2.1023. 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.1023.1. Suggestions

  • Move the default assignation to the property definition

  • Drop the reassignation in the constructor

1.2.1023.2. Specs

Short name

Classes/RedefinedDefault

Rulesets

All, CE, CI-checks, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Slow (1 hour)

Precision

Very high

Features

default-value

Examples

Piwigo

Available in

Entreprise Edition, Community Edition, Exakat Cloud