Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112451 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18426 invoked from network); 7 Dec 2020 10:01:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Dec 2020 10:01:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A047E1804DB for ; Mon, 7 Dec 2020 01:30:32 -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.7 required=5.0 tests=BAYES_05,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-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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, 7 Dec 2020 01:30:32 -0800 (PST) Received: by mail-wm1-f49.google.com with SMTP id d3so10833834wmb.4 for ; Mon, 07 Dec 2020 01:30:32 -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=622+Z99PG8UVHwNRq3v+4VLgw7QXiEytSnrLWauPI8o=; b=H6oCS8hK49LOJYi6x8y03ges8egq/pE0jtHFTU8pqkcRosujzXM4nPgIcl6wQ3RV/Y eyTYGCKje99nUNVTRz8kV4aq+KsHUQxywbBgET88qZHi5Ld4Negu+JXcHIlVZt5XIcY5 3d3NaLDqN6d4HOLryc2My74EqSUs2pRmgc+IDNTK9DY8O8dhC1ZLbZ/W/99asvsvNU/w VJdfBE3bWhE5B4o9B4o+m7V9l2KTm9iacj48pOOOIcxdMCSHYIZ22UXwsGyk2OTysWvQ 9JWn+qDQd7+WqgdoiiyKSNy13H0LceFkU7XY2k6hnzEhlh0DV/vFX/QREBozMbTzHGyA uleg== 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=622+Z99PG8UVHwNRq3v+4VLgw7QXiEytSnrLWauPI8o=; b=SZ/jsrMQv1rLvwlA019WAjzVm/DTeYAQucYxma8I0tZjS3uSf43z2fMvn9Zt9+oVb9 M4voGNjng5eYZQqmUOIlEdwnoZYpo3C59aqxSgINMpMxa1G5a4iY4BHWqkwgoF80AThz s2QJoWRAmouXFZ0zkIQwg07UDPFBHRDvyti3Uc8rAGA2qmH/7hzwDkafesLwWX7NUBcX ZGcj8evbogflOS6cPyIPktDRwXm7MFXeKHoEt1boQAdkm0M9yJkl0FUvle2dsfc4KGxF sezx1i+fvVS6Ys+cEthhmqiUHCeJ8MbmFl9m5339PKlOlJNP3SNudvH6gOy03Caeqoda RxkA== X-Gm-Message-State: AOAM532kbBDXi6BYl54oIIOacqv1KBjxckJ/2AGimszgZnag5eX/xvXA sqbrM4kH5Q50bMZCySGNAeHzIj6mO2o= X-Google-Smtp-Source: ABdhPJzJAglu8NIi2ZTgOqHQRZeE7x10EO3sokWZhhoV4uh4JzVn0WmdtQxqHZ4EMLOLlB+8qrU20A== X-Received: by 2002:a1c:2d8b:: with SMTP id t133mr2173893wmt.127.1607333429882; Mon, 07 Dec 2020 01:30:29 -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 b83sm13851116wmd.48.2020.12.07.01.30.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Dec 2020 01:30:29 -0800 (PST) To: internals@lists.php.net References: <32277b43-079d-4cd7-a159-8ad555096742@garfieldtech.com> <31c9d66b-771a-35ed-1b11-c681bbcc02c3@gmail.com> Message-ID: Date: Mon, 7 Dec 2020 09:30:27 +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 07/12/2020 01:00, Paul Crovella wrote: > Instance state being global is a well-known problem with singletons. > Maybe don't use singletons then. Or simply document them as was done > in the RFC. I'd prefer the former since singletons don't seem to buy > much here but problems, though maybe I'm missing something. Yes, I think you are missing something - or maybe I am, because I honestly can't picture what it would look like for enums *not* to be singletons. Would Suit::Hearts be a constructor, producing a new instance each time, each with its own state? Would we then overload ===, so that Suit::Hearts === Suit::Hearts was still true somehow? > In any case why is static state being (kinda sorta) restricted along with it? On the face of it, I agree, static properties could be supported. But looking at the details of the current proposal, it might actually take some thought to make them feel natural. As I understand it, each case acts like a sub-class, which is useful for over-riding instance methods, but would mean a static property would be defined separately on each case: enum Suit {     static $data;     case Hearts;     case Spades;     case Clubs;     case Diamonds; } Suit::$data = 42; $mySuit = Suit::Hearts; var_dump($mySuit::$data); // will not print 42, because Suit::Hearts::$data is a different property As Pierre says, the idea of backing enums onto objects is mostly an implementation detail; their fundamental design is based on how enums are generally used, and implemented in other languages. Rather than "objects which are a bit enum-like", it might be useful to frame them as "enums which are a bit object-like". The primary consistency needs to be with what people will expect an enum to do. Backing them onto objects makes it easy to add on any object-like behaviour that feels useful, but once we've added it, it's much harder to remove or change if we realise it's causing problems for users, or getting in the way of other features. That's why I was asking if you had use cases in mind, because I was starting from that position: assume they have *no* features, and add the ones we think are necessary and achievable. Regards, -- Rowan Tommins (né Collins) [IMSoP]