Enums

From the PHP documentation:

Enums allow a developer to define a custom type that is limited to one of a discrete number of possible values.

THP enums are a 1 to 1 map of PHP enums, with a slightly different syntax.

Basic enums

Enums don’t have a scalar value by default.

enum Suit
{
    Hearts,
    Diamonds,
    Clubs,
    Spades,
}

val suit = Suit::Heartsthp
    
Syntax error: Unexpected token `Suit`, expected a new line at line 1:5

Backed enums

Backed enums can have a scalar for each case. The scalar values can only be String or Int.

enum Suit(String)
{
    Hearts = "H",
    Diamonds = "D",
    Clubs = "C",
    Spades = "S",
}thp
    
Syntax error: Unexpected token `Suit`, expected a new line at line 1:5

All cases must explicitly define their value, there is no automatic generation.