Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112438 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19778 invoked from network); 6 Dec 2020 15:43:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Dec 2020 15:43:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D7FBE1804DD for ; Sun, 6 Dec 2020 07:11:53 -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=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.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 ; Sun, 6 Dec 2020 07:11:53 -0800 (PST) Received: by mail-wr1-f53.google.com with SMTP id m5so593561wrx.9 for ; Sun, 06 Dec 2020 07:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=3y+7g+CnMtVW6guOC/jq+OKVC2RICu5mW227JruudmI=; b=t4i26x11xpJowPJQ14ZMRApG9YyniODj5+OLrRGQkDvXIxbvYVzb6g7Win4G56E9UR pFr8nlYXsierr+laWoGs3bzaghhhPaQLXTRKTJWzNUjXJ91UfpeR4nm/cZYEbNMLGuES eOxwJ/kbbqQIXYeaySmvM76UbOQ0Yf3u46l7g1w7YWBWIQSDQNonYV8b7tLGf7EqMYSp Xy0KLEBn4a+N7sz3U+ZjICDPUjYQZGeFpqCT9ERZP4SSnTbhI/RdQ9M4pbhjbpojCqRZ 4JtDlcQUZFo5o3e4U7V32XCLo29wRq/Iq3yjmozv+kITJ9J+5IX/SZqaXk5GBCDvi8sf kH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=3y+7g+CnMtVW6guOC/jq+OKVC2RICu5mW227JruudmI=; b=M7PP7EWjFrYvk+1fZQaHAB5XS6LFIc6XMaYNHDsGUI/Sw1EULO6OnI52HWdZAtYksK uzr6p7CfelShNZlZM6fUv2xNctX6Ct9CZTtyPO1C3wYYwDKGJeaG+7FvOAizwFYNwVEV S4TvLnWXTiw9RmagyO1qFAkupRx4V9KjG+3igqJAKChyqWLyE1m4HwNAi2V8mMfNwxFp Ba0rU5CAUZF3C9NcTKRBsXZa2rOdyz9mr6vVAo/AA/9fOZCs7qLO1MBiU2NUwlXxv3fw RcbfQqNAVPWch/+GLTeP5IjWThi2f6Lgn9mLmWurvXv7yTr918hthq2WmzqJ2RrESOj1 mlCQ== X-Gm-Message-State: AOAM531NhGtKJVligp+NvgzC7x+scB09Uww5MywZ9E/K0Sj5qoOWXNma 2VRUfL/gKrMzYp5iFtn36gGR4+xtWwY= X-Google-Smtp-Source: ABdhPJzal+ov7D1Chg4LGt3YCaWISC5OXMSOwaZYUorkTnco2coRhR8Bl3PSwsCs9AdYef1eDW6mVA== X-Received: by 2002:a5d:44cf:: with SMTP id z15mr15136915wrr.205.1607267509414; Sun, 06 Dec 2020 07:11:49 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id u66sm10730464wmg.30.2020.12.06.07.11.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Dec 2020 07:11:48 -0800 (PST) To: internals@lists.php.net References: <32277b43-079d-4cd7-a159-8ad555096742@garfieldtech.com> Message-ID: <31c9d66b-771a-35ed-1b11-c681bbcc02c3@gmail.com> Date: Sun, 6 Dec 2020 15:11:47 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] Enumerations From: rowan.collins@gmail.com (Rowan Tommins) On 06/12/2020 00:17, Paul Crovella wrote: >> enum cases have no state > Unless there's a bit left out from this RFC this is not completely > true, you've just limited them to annoying ways of working with data, > e.g. static variables. I'm not sure what you mean here, but it sounds a bit like you're saying there are ways to emulate mutable state, so why bother restricting it? The point is that since enum cases are singleton objects, any instance state would actually be global across the program, which is probably not what people would expect. >> static methods on cases, which without data are exactly the same as normal methods > This is an argument against instance methods, which you kept, rather > than static methods, which you didn't. How is this division anything > but arbitrary? On a singleton object, instance methods and late static binding are equivalent, but instance methods are probably more intuitive, since people are more used to writing code like "$this->suit->shape();" than "$this->suit::shape();" I guess both could be supported, but other than more code style decisions to make, I can't think of what they'd add. > Again, what is it particular to enums that necessitates adding these > inconsistencies to the language? I get that*you* want to avoid state, > but how is that an enum thing rather than a you thing? "Inconsistency" is a straw man here, because these are a brand new concept that already does things objects don't do. So let's flip it around: do you have any use cases for directly storing state on an enum case, remembering that such state would be unavoidably global? Restricting them will likely make other desirable features easier - for instance, how would serialization work: $a = Suit::Hearts; $a->setColour(Colour::Pink); $serialized = serialize($a); // does this serialize the instance state? $a->setColour(Colour::Purple); $b = unserialize($serialized); assert($a === $b); // as discussed elsewhere, this should be true assert($a->getColour() === $b->getColour());  // are they both pink? both purple? Note that Larry's longer term plan is for "algebraic data types", including "tagged unions": https://wiki.php.net/rfc/adts Unlike straight-forward enum cases, these are not singletons, and each instance has its own associated state. Regards, -- Rowan Tommins (né Collins) [IMSoP]