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 in /codes/callTraitAlone.php on line 8
Deprecated: Calling static trait method t::foo is deprecated, it should only be called on a class using the trait in /codes/callTraitAlone.php on line 8
t::foo
PHP version change¶
This behavior was deprecated in 8.1
This behavior changed in 9.0