On 18 September 2015 08:05:11 BST, "Pavel Kouřil" <pajou...@gmail.com> wrote:
>personally, I feel that you should be able to assign numeric value to
>each element (and have them implicit if not specified).
>
>This is imho better for serialization (but it can be done with names
>as well, yeah) - but more importantly, it also allows usage with
>bitwise operators, so you could use them as a "flags" (ie. $weekend =
>Days::SATURDAY | Days::SUNDAY).

That's actually two different requests: firstly, that every enum should have a 
numeric value, rather than it being opt-in. And secondly, that enums should 
have overloaded operators that allow their use in contexts where integers would 
be expected.

I draw that distinction because overloaded operators are fairly rare in PHP 
(and largely unavailable in userland).

In some languages (e.g. C#) enums are just a name for an integer, and can be 
readily compared to, and cast from or to, ordinary integers. That's one way of 
allowing operators to work on them, but it leads to things like Days::Monday == 
Months::January returning true, which doesn't feel right to me.

I think an enum-like type specifically for bitsets, which overloaded bitwise 
operators without ever exposing the underlying integers, might be interesting, 
though.

Regards,
-- 
Rowan Collins
[IMSoP]


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to