1.2.1296. Unused Private Properties

Unused static properties should be removed.

Unused private properties are dead code. They are usually leftovers of development or refactorisation : they used to have a mission, but are now left.

Being private, those properties are only accessible to the current class or trait. As such, validating the

<?php

class foo {
    // This is a used property (see bar method)
    private $used = 1;

    // This is an unused property
    private $unused = 2;

    function bar($a) {
        $this->used += $a;

        return $this->used;
    }
}

?>

1.2.1296.1. Suggestions

  • Remove the property altogether

  • Check if the property wasn’t forgotten in the rest of the class

  • Check if the property is correctly named

  • Change the visibility to protected or public : may be a visibility refactoring was too harsh

1.2.1296.2. Specs

Short name

Classes/UnusedPrivateProperty

Rulesets

All, Dead code

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

unused

Examples

OpenEMR, phpadsnew

Available in

Entreprise Edition, Exakat Cloud