1.2.1063. Self Using Trait

Trait uses itself : this is unnecessary. Traits may use themselves, or be used by other traits, that are using the initial trait itself.

PHP handles the situation quietly, by ignoring all extra use of the same trait, keeping only one valid version.

<?php

// empty, but valid
trait a {}

// obvious self usage
trait b { use b; }

// less obvious self usage
trait c { use d, e, f, g, h, c; }

// level 2 self usage
trait i { use j; }
trait j { use i; }

?>

See also Traits.

1.2.1063.1. Suggestions

  • Remove the extra usage of the trait.

1.2.1063.2. Specs

Short name

Traits/SelfUsingTrait

Rulesets

All, Changed Behavior, Class Review, Dead code

Exakat since

1.5.7

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

High

Features

trait

Available in

Entreprise Edition, Exakat Cloud