1.2.1211. Trait Is Not A Type

A trait cannot be used for typing. It is used by a classes, and those classes should be used for typing.

<?php

trait t {}

// No way to provide an object of type t
function foo(t $t) {

}

?>

1.2.1211.1. Suggestions

  • Use the classes that use the trait as type

  • Provide an interface that matches the trait, and make the using classes implements it too

1.2.1211.2. Specs

Short name

Traits/TraitIsNotAType

Rulesets

All, Analyze, Class Review

Exakat since

2.6.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud