When a function is defined inside an enum, the use of $this appears as an undefined variable.
enum Numbers: string {
case ONE = '1';
case TWO = '2';
case THREE = '3';
case FOUR = '4';
public function divisibility(): string {
return match ($this) { // <--- Variable $this is undefined
self::ONE, self::THREE => 'odd',
self::TWO, self::FOUR => 'even',
};
}
}
When a function is defined inside an enum, the use of $this appears as an undefined variable.