<?php
enum Size: string {
case S = "S";
case M = "M";
case L = "L";
public function nextSize(): Size
{
return match($this)
{
Size::S => Size::M,
Size::M => Size::L,
Size::L => Size::S,
};
}
}
$middle = Size::M;
$next1 = $middle->nextSize();
//next1 is L
$next2 = $next1->nextSize();
//next2 is S
echo "next1 is ", $next1->value, "\n";
echo "next2 is ", $next2->value;