1.2.411. Empty Classes

Classes that do no define anything at all : no property, method nor constant. This is possibly dead code.

Empty classes are sometimes used to group classes; an interface may be used here for the same purpose, without inserting an extra level in the class hierarchy. Classes that are directly derived from an exception are omitted.

<?php

//Empty class
class foo extends bar {}

//Not an empty class
class foo2 extends bar {
    const FOO = 2;
}

//Not an empty class, as derived from Exception
class barException extends \Exception {}

?>

See also class.

1.2.411.1. Connex PHP features

1.2.411.1.1. Suggestions

  • Remove the empty class: it is possibly dead code.

  • Add some code to the class to make it concrete.

  • Turn the class into an interface.

1.2.411.1.2. Specs

Short name

Classes/EmptyClass

Rulesets

All, Analyze, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Examples

WordPress

Available in

Entreprise Edition, Exakat Cloud