Accessing Directly Properties In Trait
I was possible, though deprecated, to manipulate directly trait properties: the static properties.
Since traits only make sense as a part of a class, this operation is now forbidden.
Accessing static methods are also forbidden. Accessing trait constants is also forbidden, although constants in traits were introduced in PHP 8.3.
PHP code
<?php
trait T {
public static $P = 1;
}
echo T::$P;
?>
Before
1
After
PHP Deprecated: Accessing static trait property t::$P is deprecated, it should only be accessed on a class using the trait
Deprecated: Accessing static trait property t::$P is deprecated, it should only be accessed on a class using the trait
1
PHP version change
This behavior was deprecated in 8.0.
This behavior changed in 8.1.