Cannot Call Traits Methods Directly
Traits used to be called directly, like a class. In PHP 8.1, this feature has been removed. The methods, properties or constants of the trait must be called in the context of their host class.
PHP code
<?php
trait T {
static function foo() { echo __METHOD__; }
}
echo T::foo();
?>
Before
t::foo
After
PHP Deprecated: Calling static trait method t::foo is deprecated, it should only be called on a class using the trait
Deprecated: Calling static trait method t::foo is deprecated, it should only be called on a class using the trait
t::foo
PHP version change
This behavior was deprecated in 8.1.
This behavior changed in 9.0.