Calling static trait method %s::%s is deprecated

Description

Traits cannot be used independently from a host class. They must be used inside a class, with the use keyword.

Until PHP 8.1, it was possible to call traits without a host class. Since 8.1, calling a trait method is deprecated.

It is also not possible to call a method or a property on a trait.

Example

<?php

trait T {
     public static function foo() { echo __METHOD__; };
}

t::foo();

?>

Literal Examples

  • Calling static trait method T::foo is deprecated

Solutions

  • Use the trait in a class and access its features.

  • Convert the trait into a class and access its features.