Constants In Trait

Trait can have constants in PHP 8.3 and later. Until that version, constants cannot be set in traits, and end with a compilation error.

PHP code

<?php

trait T {
    const X = 1;
}

class X {
     use T;
}

echo X::X;

?>

Before

PHP Fatal error:  Traits cannot have constants

After

1

PHP version change

This behavior changed in 8.3

Error Messages