1.2.107. Cannot Call Static Trait Method Directly¶
<?php
trait t { static public function t() {}}
a::t();
// OK
t::t();
//Calling static trait method t::t is deprecated, it should only be called on a class using the trait
class a {
use t;
}
?>
See also Calling a static element on a trait.
1.2.107.1. Suggestions¶
Use the trait in a class, and call the method from the class.
1.2.107.2. Specs¶
Short name |
Traits/CannotCallTraitMethod |
Rulesets |
|
Exakat since |
2.3.1 |
PHP Version |
With PHP 8.1 and older |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Features |
trait, static-method |
Available in |