1.2.1220. 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.1220.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.1220.2. Specs¶
Short name |
Traits/TraitIsNotAType |
Rulesets |
|
Exakat since |
2.6.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |