# [RFC]: Allow static properties in enums

- Thread: https://externals.io/message/114494
- Original archive: https://news-web.php.net/php.internals/114494
- Started by tyson andre on 2021-05-17T14:01:57+00:00
- Messages: 6
- RFC: Allow static properties in enums (Declined) — https://externals.io/rfc/enum_allow_static_properties.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

---

## #114494 — tyson andre — 2021-05-17T14:01:57+00:00

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

Hi internals,

I've created a new RFC https://wiki.php.net/rfc/enum_allow_static_properties

Although enums are immutable objects, it is often useful to have functions or methods that operate on enum instances.
In many cases, it would make sense to declare that functionality as static methods on the enum itself.
In cases where static methods require shared state, it would be useful to allow storing those shared state in static properties.
To ensure immutability of enum instances, it's only necessary to forbid instance properties, but all properties were forbidden in the initial functionality included with the enums RFC.

This RFC proposes allowing static properties in enums, while continuing to forbid instance properties.

Thanks,
Tyson

---

## #114495 — michal.brzuchalski@gmail.com — 2021-05-17T14:16:27+00:00

URL: https://externals.io/message/114494#114495 · In reply to: #114494

pon., 17 maj 2021, 16:02 użytkownik tyson andre <tysonandre775@hotmail.com>
napisał:

> Hi internals,
>
> I've created a new RFC
> https://wiki.php.net/rfc/enum_allow_static_properties
>
> Although enums are immutable objects, it is often useful to have functions
> or methods that operate on enum instances.
> In many cases, it would make sense to declare that functionality as static
> methods on the enum itself.
> In cases where static methods require shared state, it would be useful to
> allow storing those shared state in static properties.
> To ensure immutability of enum instances, it's only necessary to forbid
> instance properties, but all properties were forbidden in the initial
> functionality included with the enums RFC.
>
> This RFC proposes allowing static properties in enums, while continuing to
> forbid instance properties.
>

Would you be able to provide more real life example?
The example in RFC could easily encapsulate current Environment reading in
for eg. EnvironmentConfiguration class with static property and method and
TBH possibly that would be my preference to solve this.

Cheers,
Michał Marcin Brzuchalski

---

## #114497 — Larry Garfield — 2021-05-17T14:29:10+00:00

URL: https://externals.io/message/114494#114497 · In reply to: #114495

> pon., 17 maj 2021, 16:02 użytkownik tyson andre <tysonandre775@hotmail.com>
> napisał:
> 
> > […]
> 
> Would you be able to provide more real life example?
> The example in RFC could easily encapsulate current Environment reading in
> for eg. EnvironmentConfiguration class with static property and method and
> TBH possibly that would be my preference to solve this.

I would agree.  Static properties are ugly to begin with.  They're globals with extra syntax.  I have no desire to see them on enums.

Also a clarification, since it wasn't entirely clear in Tyson's original email: Static methods on Enums *are already supported*.  They were included in the original Enum RFC.  The change proposed here is just about static properties.

--Larry Garfield

---

## #114506 — michal.brzuchalski@gmail.com — 2021-05-17T15:58:10+00:00

URL: https://externals.io/message/114494#114506 · In reply to: #114497

pon., 17 maj 2021, 16:31 użytkownik Larry Garfield <larry@garfieldtech.com>
napisał:

> 
> > […]
> tysonandre775@hotmail.com>
> > […]
> functions
> > […]
> static
> > […]
> to
> > […]
> continuing to
> > […]
> in
> > […]
> and
> > […]
>
> I would agree.  Static properties are ugly to begin with.  They're globals
> with extra syntax.  I have no desire to see them on enums.
>
> Also a clarification, since it wasn't entirely clear in Tyson's original
> email: Static methods on Enums *are already supported*.  They were included
> in the original Enum RFC.  The change proposed here is just about static
> properties.
>

Personally, I'd prefer to see enums as value objects only, adding static
properties allow to implementation of statically conditional behaviour.
IMO enums should consist only of pure functions. This is why I'd vote NO on
this proposal.

Cheers,
Michał Marcin Brzuchalski

---

## #114510 — tyson andre — 2021-05-18T00:46:40+00:00

URL: https://externals.io/message/114494#114510 · In reply to: #114506

> > […]
> 
> Personally, I'd prefer to see enums as value objects only, adding static
> properties allow to implementation of statically conditional behaviour.
> IMO enums should consist only of pure functions. This is why I'd vote NO on
> this proposal.
> 
> Cheers,
> Michał Marcin Brzuchalski

Hi internals,

I've updated https://wiki.php.net/rfc/enum_allow_static_properties to include the arguments made so far against/for including
static properties, as well as including more arguments/examples in favor of including static properties in traits.

Thanks,
- Tyson

---

## #114668 — tyson andre — 2021-05-30T14:31:00+00:00

URL: https://externals.io/message/114494#114668 · In reply to: #114494

Hi internals,

> I've created a new RFC https://wiki.php.net/rfc/enum_allow_static_properties
> 
> Although enums are immutable objects, it is often useful to have functions or methods that operate on enum instances.
> In many cases, it would make sense to declare that functionality as static methods on the enum itself (which is already permitted).
> In cases where static methods require shared state, it would be useful to allow storing those shared state in static properties.
> To ensure immutability of enum instances, it's only necessary to forbid instance properties, but all properties were forbidden in the initial functionality > included with the enums RFC.
> 
> This RFC proposes allowing static properties in enums, while continuing to forbid instance properties.

I plan to start voting on https://wiki.php.net/rfc/enum_allow_static_properties on June 1, 2021
 
Regards,
Tyson
