1.2.282. Could Set Property Default

When a property is set to a literal in the constructor, the assignation may be moved to the property definition.

It is a micro-optimisation.

<?php

class x {
    private $p;
    private $p2;

    function __construct($d) {
        // dynamic default value.
        $this->p = $d;

        $this->p2 = "2";
    }

}

?>

1.2.282.1. Suggestions

  • Set the default value to the property declaration, and remove the assignation in the constructor

1.2.282.2. Specs

Short name

Classes/CouldSetPropertyDefault

Rulesets

All, Changed Behavior, Class Review, Suggestions

Exakat since

2.4.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud