RFC Karma request: Enums with Associated Values for cases

From: Date: Wed, 04 Feb 2026 12:16:36 +0000
Subject: RFC Karma request: Enums with Associated Values for cases
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-130006@lists.php.net to get a copy of this message
Hello, I would like to get RFC Karma for my wiki account. My username is: jkroon. The proposed RFC will introduce Enums with Associated Values for cases and is inspired by Rust and Swift. For example it would allow for the following: ``` <?php enum ApiResult {     case Success(string $data, int $statusCode);     case Failure(Throwable $error, ?int $statusCode); } function handle(ApiResult $r): string {     return match ($r) {         ApiResult::Success => 'OK ' . $r->statusCode . PHP_EOL,         ApiResult::Failure => 'NO ' . ($r->statusCode ?? 'unknown') . PHP_EOL,     }; } echo handle(ApiResult::Success('All good', 200)); echo handle(ApiResult::Failure(new Exception('Bad request'), 400)); echo handle(ApiResult::Failure(new Exception('Server error'), null)); ``` Regards, Jordi

« previous php.internals (#130006) next »