Traits cannot have constants¶
Description¶
Constants were authorised in traits in PHP 8.2. Until then, they are not allowed, at compile time.
Example¶
<?php
trait t {
const X = 1;
}
echo t::X;
?>
Solutions¶
Put the constant in the host class.
Put the constant in an interface.
Do not use the constant.