1.2.892. Overwritten Class Constants

Those class constants are overwriting a parent class’s constant. This may lead to confusion, as the value of the constant may change depending on the way it is called.

<?php

class foo {
    const C = 1;
}

class bar extends foo {
    const C = 2;

    function x() {
        // depending on the access to C, value is different.
        print self::C.' '.static::C.' '.parent::C;
    }
}

?>

1.2.892.1. Suggestions

  • Remove the constant in the interface

  • Remove the constant in the class

  • Rename one of the constants

1.2.892.2. Specs

Short name

Classes/OverwrittenConst

Rulesets

All, Appinfo, CE

Exakat since

0.8.4

PHP Version

All

Severity

Time To Fix

Precision

High

Features

class-constant, overwrite

Available in

Entreprise Edition, Community Edition, Exakat Cloud