On 04/01/2021 22:04, Mike Schinkel wrote:
I don't quit get how you are thinking of with ": string"; can you give an
example?
The current RFC requires the declaration of a Scalar Enum [1] to include
the scalar type, so it looks like this:
enum BookingStatus: string {
case PENDING = "PENDING";
case CONFIRMED = "CONFIRMED";
case CANCELLED = "CANCELLED";
}
The simplest opt-in for default scalar values would be to declare the
type but no values, so the above could be abbreviated this way:
enum BookingStatus: string {
case PENDING;
case CONFIRMED;
case CANCELLED;
}
However, it's probably better to be a bit more explicit, e.g.:
enum BookingStatus: auto string {
case PENDING;
case CONFIRMED;
case CANCELLED;
}
Either way, we'd have to decide if it was allowed to specify some values
but not all, e.g.:
enum BookingStatus: auto string {
case PENDING;
case CONFIRMED;
case CANCELLED = 'TERMINATED';
}
A more verbose but possibly clearer syntax would be a token on the case
statements themselves, such as "= auto", to mean "set the value for this
case based on its constant name":
enum BookingStatus: string {
case PENDING = auto;
case CONFIRMED = auto;
case CANCELLED = 'TERMINATED';
}
There's also the question of whether an automatic value for ints should
also be allowed, e.g. incrementing in declaration order. This is more
dangerous, as adding, removing, or re-arranging cases can affect the
values of *all* the cases in the enum, but is done in some other languages.
[1] https://wiki.php.net/rfc/enumerations#scalar_enums
Regards,
--
Rowan Tommins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php