Accessing static trait property %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, writing or reading properties in a trait is forbidden.
It is also not possible to call a method or a constant on a trait.
Example¶
<?php
trait T {
public static $t = 1;
}
echo T::$t;
T::$t = 2;
?>
Literal Examples¶
Accessing static trait property T::$property is deprecated
Solutions¶
Use the trait in a class and access its features.
Convert the trait into a class and access its features.