Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112990 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65950 invoked from network); 25 Jan 2021 17:23:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Jan 2021 17:23:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 533A71804E2 for ; Mon, 25 Jan 2021 09:04:44 -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: Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 ; Mon, 25 Jan 2021 09:04:44 -0800 (PST) Received: by mail-ed1-f53.google.com with SMTP id d2so12739435edz.3 for ; Mon, 25 Jan 2021 09:04:44 -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=n6HqrZS18d8C3SvTXFtsf3rYv3YCRAVP/WOX7BwY/t0=; b=GDuYWT6ZnGS2ZP3M19p/YW5JqMnXbbe1ImpUJrl+4/uXoMUD1btCMYNxcDK4jUnArQ 6LVIQCb0cO1BZ1RPcvceCquuQSJoiv3ji1kKLevaVNooTFy5sVD2JXzFnwdscoQRmOEm Mdg3DykBA6FrVPhyhfQiziTvCDumZOe3nu3FbTsyJs+ge2i/JGdaLgJf7VjRp1udMzI+ qee1IkvZnQwBSxfhobRnAgdveAa0mGNRJEbECdpAL2o7+0XIJe4RuP+kOdrV6mOtS+NM YxJ1EuWuuAEvSeRWA39nDj5nIRK1J8U/1h39RctH7U8We9TgvWNE0CUYN/j+GMvVSN+U XDog== 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=n6HqrZS18d8C3SvTXFtsf3rYv3YCRAVP/WOX7BwY/t0=; b=PPBk6OFclQYeajrfrnp9T3p+oiAqoEmfOUhn1OtxEJb4xa9yHlhbNZvbYkgoaDb3Te XoO02aoc2w5xwydxYZWQ9Olpg1AuhdBptVvB7axldfA38a9FsSJ8XMTdXoGHVYGcbDzN I8H3yf1NSDXIAAcYF+dkwaoWzHi5EwIuReBNW8zlbvhcIa937OqAuCdEePbHkCD/szpf EpIh+b84DlQR+3/dGFUdiuZdQFCvcmj4jL/7MbwAhLUSkLy2HO8xiFzpcBfFixRjNKAU B/KZMCU/PcKg+CDYlEQSlZBtTU/kgqri/VzCSkZlTrPk4AJ5S4CX0OReHhGxLocK+nWu rnAA== X-Gm-Message-State: AOAM5301lt6dMaLp7ApdjOyBGWfQhk5ryETGiqcAe83LAHgmAJeNsL1s YuFeijOL/5j+MlIk149wHrhbu9SB155PLSVwhHNIXBx00d8AZQ== X-Google-Smtp-Source: ABdhPJziiKU+Tj/DMGXnbNIgnycEnGGYDhiC1DhqpSoTX+lnAbcmWUitbdHmw23GzWD8i9JoTlAb5PIBDM7VjGnCELw= X-Received: by 2002:a05:6402:3116:: with SMTP id dc22mr1212865edb.325.1611594283018; Mon, 25 Jan 2021 09:04:43 -0800 (PST) MIME-Version: 1.0 References: <8f17a7b3-2488-461f-9756-d675b1dc0981@www.fastmail.com> In-Reply-To: <8f17a7b3-2488-461f-9756-d675b1dc0981@www.fastmail.com> Date: Mon, 25 Jan 2021 17:04:32 +0000 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000c2ea2805b9bc88bc" Subject: Re: [PHP-DEV] [RFC] Enumerations, Round 2 From: george.banyard@gmail.com ("G. P. B.") --000000000000c2ea2805b9bc88bc Content-Type: text/plain; charset="UTF-8" On Mon, 25 Jan 2021 at 02:29, Larry Garfield wrote: > Aside from some nitpicking around reflection and possibly fiddling with > the naming of "Scalar Enum" et al, we're closing in on the final version. > It will probably go to a vote in the not too distant future. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Most of this has already been communicated off list but I ought to make my opinions on the proposal somewhat "official". Although I do think we need enums backed into PHP, I'm really not keen on piggy backing on objects. I'm also aware that this would be a larger undertaking as using objects as one would need to rewrite part of the logic objects use. However, looking at how much of the objectness needs to be blocked and/or modified (traits, final, no properties, etc.), IMHO, points towards a new zval structure instead of reusing objects, at least for the simple cases as a simple enumeration set or a scalar backed enumeration set which don't need any methods. Moreover, the implementation details of it leak quite a lot and I'm not really a fan of having the reflection class of enum extend the class one. My reasoning is that, albeit extremely clunky, one can already achieve the kind of enumeration proposed here in userland, in a type safe fashion, in PHP 8.0 by using union types: final class Heart {} final class Clubs {} final class Spades {} final class Diamond {} final class Suit { public function __construct(private Heart|Clubs|Spades|Diamond $value) {} public function value() { return $this->value; } } This form is basically reducing an ADT to an enumeration, and in any case introducing additional syntax to alleviate the verbosity of this is a separate concern. (to see this somewhat in action I've written some slides for small university talk which demonstrates how it can be used [1][2]). The final concern, which might be non-existent as there is no mention of it in the RFC, is OPcache. My understanding of OPcache is fairly limited, but IIRC caching and optimizing things around objects is extremely complicated if not at all impossible, wouldn't this rather severe limitation also apply to enums, even for basic lists? Or are all the objectness restrictions placed on enums sufficient to make this a non-issue? As such, unless convinced otherwise, I don't think I will personally support this proposal. Best regards, George P. Banyard [1] https://slides.com/girgias/reflection-algebraic-data-types-for-mortals#/5/5 [2] https://slides.com/girgias/reflection-algebraic-data-types-for-mortals#/5/6 --000000000000c2ea2805b9bc88bc--