1.2.1402. Useless Override Attribute

The override attribute is only useful on an extended class. It allows to mark a method that must be overriding a parent method. When the class is not extending another class, there is no point in using this attribute.

This is also valid with extended class : the top parent class has no use of the override.

There is a dedicated compile-time error.

<?php

class x {
     // override in that trait are useless
     use t;

     // This is useless
     #[Override]
     function foo() {}
}

trait t {
     // This is useless if loaded in a root class
     #[Override]
     function foo() {}
}

enum e {
     // This is useless in any case
     #[Override]
     function foo() {}
}


?>

1.2.1402.1. Connex PHP features

1.2.1402.1.1. Specs

Short name

Attributes/UselessOverride

Rulesets

All, Analyze, Attributes

Exakat since

2.6.8

PHP Version

With PHP 8.0 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud