# RFC Karma request: Enums with Associated Values for cases

- Thread: https://externals.io/message/130007
- Original archive: https://news-web.php.net/php.internals/130007
- Started by Larry Garfield on 2026-02-04T14:35:18+00:00
- Messages: 1
- RFC: Pattern matching is keyword (Under discussion) — https://externals.io/rfc/pattern-matching.md
- RFC: Tagged Unions (Enums) (Inactive) — https://externals.io/rfc/tagged_unions.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #130007 — Larry Garfield — 2026-02-04T14:35:18+00:00

URL: https://externals.io/message/130007#130007

> 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

Please be aware that there are already plans for this feature (RFC is a bit dated for now so don't take literally):

https://wiki.php.net/rfc/tagged_unions

Which is currently blocked pending pattern matching, currently in discussion:

https://wiki.php.net/rfc/pattern-matching

I'm regularly around the phpc.chat Discord if you want to talk about it more directly.  Right now the main blocker is time availability, and getting pattern matching done.  (See it's thread for the currently open questions.)

--Larry Garfield
