1.2.890. Override

Override is a native PHP attribute. It was introduced in PHP 8.3, and was not available before.

In fact, static analysis can perform that check on previous versions of PHP.

Override signals that the class has a method which overrides the parent’s definition. If there is no such method in a parent, an error is raised.

This analysis is not valid after PHP 8.3, as PHP does that itself.

<?php

class x {
     function foo() {}
}

class y extends x {
     // OK, there is a method in the class above
     #[Override]
     function foo() {}

     // KO, there is no such method in the class above
     #[Override]
     function hoo() {}
}


?>

See also PHP RFC: Marking overridden methods (#[Override]) and PHP 8.3 RFC: Marking overridden methods (#[Override]).

1.2.890.1. Suggestions

  • Change the name of the current method to match an existing one

  • Remove the method

  • Remove the attribute

1.2.890.2. Specs

Short name

Attributes/Override

Rulesets

All, Attributes

Exakat since

2.6.1

PHP Version

From PHP 8.0 to 8.3

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud