# Enum + property hook getter

- Thread: https://externals.io/message/126332
- Original archive: https://news-web.php.net/php.internals/126332
- Started by Marc Bennewitz on 2025-02-07T15:03:15+00:00
- Messages: 3
- 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

---

## #126332 — Marc Bennewitz — 2025-02-07T15:03:15+00:00

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

Hi all,

Enums are not allowed to include object properties and with property 
hooks it's now possible to define get-only dynamic properties.

I just come across the following example and wonder if this could be 
allowed in the future:

enum Month:int {
     case January = 1;
     case February = 2;
     case March = 3;
     case April = 4;
     case May = 5;
     case June = 6;
     case July = 7;
     case August = 8;
     case September = 9;
     case October = 10;
     case November = 11;
     case December = 12;

     public string $abbreviation {
         get => substr($this->name, 3);
     }
}

Means, allowing get-only property hooks on enums reducing the need to 
write "old school" getter methods.

Is that something feasible and how complicated would that be to implement?

Best,
Marc Bennewitz

---

## #126334 — tim@bastelstu.be — 2025-02-07T15:11:00+00:00

URL: https://externals.io/message/126332#126334 · In reply to: #126332

Hi

Am 2025-02-07 16:03, schrieb Marc Bennewitz:
> Is that something feasible and how complicated would that be to 
> implement?

Supporting this might cause conflicts when full-blown tagged-unions are 
proposed, because those would actually support properties and semantics 
might need to be different than those a naive “rushed” implementation of 
property hooks for enums would propose.

See https://wiki.php.net/rfc/tagged_unions for an very early draft 
(which is not in a shape to be discussed further).

Best regards
Tim Düsterhus

---

## #126358 — Marc Bennewitz — 2025-02-09T06:33:05+00:00

URL: https://externals.io/message/126332#126358 · In reply to: #126334

Hi Tim,

Unintentionally, I first replied to Tim only but it was meant to be send 
to the list.


> Hi
>
> Am 2025-02-07 16:03, schrieb Marc Bennewitz:
> > […]
>
> Supporting this might cause conflicts when full-blown tagged-unions 
> are proposed, because those would actually support properties and 
> semantics might need to be different than those a naive “rushed” 
> implementation of property hooks for enums would propose.
>
> See https://wiki.php.net/rfc/tagged_unions for an very early draft 
> (which is not in a shape to be discussed further).

I see - that would actually be a very nice feature - looking forward to it.

First thought it might have been overlooked and just not included for 
simplicity, but yes, tagged union looks much more impressive.

Thanks for your helpful explanation!

> Best regards
> Tim Düsterhus

Best,
Marc Bennewitz
