1.2.12. Abstract Class Constants

Those are class constants which are defined in multiple children, but not in the parent class.

If this class is a feature of the parent class, or shall and must be defined in the children classes, it is recommended to add them in the parent class, and let them overloaded in the children class.

In the illustration below, CONSTA is defined in all two children, but not in the parent class. A third children would miss the constants definitions, until an error has been reported.

<?php

class A {
    // no constant
}

class A1 extends A {
    public const CONSTA = 1;
}

class A2 extends A {
    public const CONSTA = 2;
}

?>

Name

Default

Type

Description

minimum

2

integer

Minimal number of constant found in children to report this as a potential abstract class.

See also I often find myself wishing for abstract constants in PHP.

1.2.12.1. Suggestions

  • Define the constants in the parent class, with some neutral value

1.2.12.2. Specs

Short name

Classes/AbstractConstants

Rulesets

All, Changed Behavior, Class Review

Exakat since

2.3.3

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Features

class-constant, abstract

Available in

Entreprise Edition, Exakat Cloud