1.2.733. Multiple Identical Trait Or Interface

There is no need to use the same trait, or implements the same interface more than once in a class.

Up to PHP 7.4, this doesn’t raise any warning. Traits are only imported once, and interfaces may be implemented as many times as wanted.

Since PHP 7.4, multiple implementations of the same interface in one class is reported at compilation time. It is possible to repeat the implementation in various levels of a class hierarchy (aka, same implements in a class and a parent).

This only applies in a single class: there are no checks in a class, or interface hierarchy.

<?php

class foo {
    use aTrait, aTrait, aTrait;
    use aTrait;
}

class bar implements anInterface, anInterface, anInterface {

}

?>

See also Already Parents Interface.

1.2.733.1. Suggestions

  • Remove the duplicate trait or interface

1.2.733.2. Specs

Short name

Classes/MultipleTraitOrInterface

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

Very high

Features

trait

Available in

Entreprise Edition, Community Edition, Exakat Cloud