phpbeginner
PHP 8 Enum and Match Expression
Clean status enum with exhaustive match return expression
By ApeType Staff·14 lines·384 characters·1,420 total attempts
<?php
enum HttpStatus: int {
case OK = 200;
case NOT_FOUND = 404;
case SERVER_ERROR = 500;
public function message(): string {
return match($this) {
self::OK => "Request completed successfully",
self::NOT_FOUND => "The requested resource was not found",
self::SERVER_ERROR => "Internal server error occurred",
};
}
}
TRANSCRIBE
Ready when you are.
Test your muscle memory and transcription speed against this exact snippet.
Start Typing
Tip: Press Esc anytime to restart
Best runs on this snippet
No recorded runs yet. Be the first to type this snippet!