Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:112656
Return-Path: <drealecs@gmail.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 17075 invoked from network); 30 Dec 2020 10:38:34 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 30 Dec 2020 10:38:34 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 61C4D1804C4
	for <internals@lists.php.net>; Wed, 30 Dec 2020 02:13:14 -0800 (PST)
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net
X-Spam-Level: 
X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,
	RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS
	autolearn=no autolearn_force=no version=3.4.2
X-Spam-Virus: No
X-Envelope-From: <drealecs@gmail.com>
Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by php-smtp4.php.net (Postfix) with ESMTPS
	for <internals@lists.php.net>; Wed, 30 Dec 2020 02:13:10 -0800 (PST)
Received: by mail-ed1-f42.google.com with SMTP id b2so14984369edm.3
        for <internals@lists.php.net>; Wed, 30 Dec 2020 02:13:10 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc;
        bh=8Q+0NX2XKTPW8pocsbkv9tf82SFCGmmAgNmDFz5Yj/M=;
        b=j04RkPyr+Ya3yi4Ho+2OoDEazizOW93v4rz1GeEA78HYLqN5WJVCbdT4YxHdazkyRd
         DzdyOHpZE/4zGSoWwoROv3s9LiOj6KxQBXha5oEeLW+nEuY58ndOQ6/nTpSCRXXHggle
         TgBthLboFnTDb4UT8PXkKPBvKUxo1K887ww6kzpIdfUS+vSpNLwnVL0jmUhr/D/cvU48
         LWq2zF2gPuJNkqRFN/D+q9WTSF/7YKwl8zWgHwIi7QtyfpuFDkNkLmAuj0cNpc2mjzPl
         JlC+kgPvdW4rs6TzqvVvyPhXND70bifJAH6qFAPrL7abTffiHEX0GymuWExCyCfSerlF
         7x0w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc;
        bh=8Q+0NX2XKTPW8pocsbkv9tf82SFCGmmAgNmDFz5Yj/M=;
        b=Dh1dWo+K76XvuMnQ+XYN5Gjkmp5+IqJTPgrHcBoDSDI/dQk84KJ8/ZwYZnFipJf530
         wMNtMIvMZ/9tIvpPJ6eN5drYwst6oFpTin42a4yb4U/expl6v61bUNLEsSLcvRA4dfMU
         x2n9zuIqhCgGJt+jxbI5LHfnpXdZ4u1A0FbOy2CgtiKoqdd5nXaxweMuFqPQ2k4HYYfV
         BEUnmccnp4EUk6vrQFbMG6tJ09+omUurp8XQ565pFs+XkDGBJpWTBP4u82Id4zZhere1
         hUhZU3Qq97Z1zbSIqVXdeuFx1j0WW4+5tU++4PzJYgfzAkoVWqz390LUhQ2Dw3laf1dZ
         E8sg==
X-Gm-Message-State: AOAM533e9lTalGLV46SFjHaN3KCb+Bpps05qA0Tu1DDlfBzbX7aCGQJF
	IARapJ/WmrbS6vfvoLk/M1JyoX0oJpAyYHmB0fQ=
X-Google-Smtp-Source: ABdhPJzraHUejtrYyPaMX9GA8YkW0JzEq14X9aY9VtKIVzxkIS/ryChc8qC0MBER70FIvUGmIzhNQEZmpo6EiG44a1c=
X-Received: by 2002:a05:6402:190c:: with SMTP id e12mr49140599edz.388.1609323188851;
 Wed, 30 Dec 2020 02:13:08 -0800 (PST)
MIME-Version: 1.0
References: <eadd4a32-a05b-463b-a91f-a5d353c577b2@www.fastmail.com>
In-Reply-To: <eadd4a32-a05b-463b-a91f-a5d353c577b2@www.fastmail.com>
Date: Wed, 30 Dec 2020 12:12:52 +0200
Message-ID: <CAAwdEzCLVsaoWhmOV8PnELQwaWeUjCJeomqr12H8f1KesKZnQg@mail.gmail.com>
To: Larry Garfield <larry@garfieldtech.com>
Cc: php internals <internals@lists.php.net>
Content-Type: multipart/alternative; boundary="00000000000000197e05b7abc1b7"
Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2
From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=)

--00000000000000197e05b7abc1b7
Content-Type: text/plain; charset="UTF-8"

On Mon, Dec 28, 2020 at 10:22 PM Larry Garfield <larry@garfieldtech.com>
wrote:
>
> Hello, Internalians!
>
> After considerable discussion and effort, Ilija and I are ready to offer
you round 2 on enumerations.  This is in the spirit of the previous
discussion, but based on that discussion a great deal has been reworked.
The main change is that Enumeration Cases are now object instances of the
Enumeration class rather than their own class.  Most of the other changes
are knock-on effects of that.
>
> Of particular note:
>
> * Cases may not have methods or constants on them.  They're just dumb
values.
> * Enums themselves may have methods, static methods, or constants.
> * Traits are supported, as long as they don't have properties.
> * The value() method on scalar enums is now a property.
>
> The full RFC is here, and I recommend reading it again in full given how
much was updated.
>
> https://wiki.php.net/rfc/enumerations
>
> The implementation is 98% complete; there's still a few lagging bits in
reflection, and some opcache bugs that Ilija is still stomping on.
>
> There are a few outstanding questions listed that we would like feedback
on.  We're not entirely certain which direction to go with them, for
reasons explained in the RFC.  Input on those is especially welcome.
>
> Happy New Year.  May it be enumerable.
>
> --
>   Larry Garfield
>   larry@garfieldtech.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: https://www.php.net/unsub.php
>

Hi!

Nice evolution overall.

Few notes:
- I think ScalarEnum::fromValue() would be more clear than just from() and
more in sync with ->value property.
- For the class structure you gave an example to illustrate the 'similar'
way it is related to class, it would be nice to also mark the class as
final.
- I agree with no state behavior, at least at this point. However, I would
have liked to offer the ability for very easy creation of
singleton/multiton patterns using enums, like in Java.
- Enums evolve in time and cases are added or sometimes removed. When the
storage of the case stays externally (as scalar values or serialized),
there could be issues when some of them are removed in the meantime.
  - for ScalarEnum::from(), for missing values I would guess we will throw
an exception, maybe a specific one? Can we mention it in the RFC?
  - for deserialization, how should it be handled? using an exception as
well, same exception as in the previous case.
- The allowed_classes option on unserialize() method, I'm guessing it will
work with Enums just like every other class, putting an instance of
__PHP_Incomplete_Class?
- Inheritance would work between enums. But only by eliminating some cases.
I can see how enum RedSuites could extend enum Suites without breaking LSP.
Not sure if it makes sense to dig on this now.

Regards,
Alex

--00000000000000197e05b7abc1b7--