enum Status
{
case DRAFT;
case PUBLISHED;
case ARCHIVED;
}
enum Status: string
{
case DRAFT = 'draft';
case PUBLISHED = 'published';
case ARCHIVED = 'archived';
}
$name = Status::PUBLISHED->name;
$value = Status::PUBLISHED->value;
$status = Status::from(2);
$status = Status::from('unknown');
$status = Status::tryFrom('unknown');
Status::cases();
enum Status: int
{
case DRAFT = 1;
case PUBLISHED = 2;
case ARCHIVED = 3;
}
enum Status
{
case DRAFT;
case PUBLISHED;
case ARCHIVED;
public function color(): string
{
return match($this)
{
Status::DRAFT => 'grey',
Status::PUBLISHED => 'green',
Status::ARCHIVED => 'red',
};
}
}