Accessing Directly Properties In Trait

Until PHP 8.1, it was possible, though deprecated, to manipulate directly trait properties: the static properties.

Since trait 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

Error Messages

Analyzer