1.2.109. Cannot Call Static Trait Method Directly

From the migration docs : Calling a static method, or accessing a static property directly on a trait is deprecated. Static methods and properties should only be accessed on a class using the trait.

<?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.109.2. Connex PHP features

1.2.109.2.1. Suggestions

  • Use the trait in a class, and call the method from the class.

1.2.109.2.2. Specs

Short name

Traits/CannotCallTraitMethod

Rulesets

All, Analyze, Changed Behavior, CompatibilityPHP81, CompatibilityPHP82

Exakat since

2.3.1

PHP Version

With PHP 8.1 and older

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud