One or more class constants have been defined inside a trait. The class constants can only be defined inside a class. Defining class constants outside a class can lead to runtime errors.
It is recommended to extract these class constants inside a standalone class. If you are using PHP 8.1 or later, you can also use Enumeration constants to define these generic constants.
trait StatusTrait
{
// invalid: a trait can't have constants
public const DRAFT = 'draft';
public const PUBLISHED = 'published';
public const ARCHIVED = 'archived';
}
class Status
{
public const DRAFT = 'draft';
public const PUBLISHED = 'published';
public const ARCHIVED = 'archived';
}
Or, use enumeration constants(Only supported in PHP 8.1 and later):
enum Status
{
public const DRAFT = 'draft';
public const PUBLISHED = 'published';
public const ARCHIVED = 'archived';
}