1.2.458. Final Constant

This rule lists the usage of the final modifier for class constants. The support of final for class constants was added in PHP 8.1.

<?php

class MyClass {
    final const X = 1; // This constant cannot be redefined

    const Y = 2; // This constant might be redefined in a child

    private const Z = 3; // This private, and can't be made final, because it is not available anyway
}

?>

See also https://www.php.net/manual/en/language.oop5.final.php and https://php.watch/versions/8.1/final-class-const.

1.2.458.1. Specs

Short name

Php/FinalConstant

Rulesets

All, Appinfo, Changed Behavior, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80

Exakat since

2.3.0

PHP Version

With PHP 8.1 and more recent

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

final-class-constant

Available in

Entreprise Edition, Exakat Cloud