1.2.460. Final Private Methods

PHP’s private methods cannot be overwritten, as they are dedicated to the current class. That way, the final keyword is useless.

PHP 8.0 warns when it finds such a method.

<?php

class foo {
    // Final and private both prevent child classes to overwrite the method
    final private function bar() {}

    // Final and protected (or public) keep this method available, but not overwritable
    final protected function bar() {}
}

?>

See also Final Keyword.

1.2.460.1. Suggestions

  • Remove the final keyword

  • Relax visibility

1.2.460.2. Specs

Short name

Classes/FinalPrivate

Rulesets

All, CE, Class Review, CompatibilityPHP80

Exakat since

2.2.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

final

Available in

Entreprise Edition, Community Edition, Exakat Cloud