Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119767 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42075 invoked from network); 29 Mar 2023 11:02:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2023 11:02:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D5BF6180511 for ; Wed, 29 Mar 2023 04:02:02 -0700 (PDT) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 29 Mar 2023 04:02:02 -0700 (PDT) Received: by mail-vs1-f44.google.com with SMTP id d18so12935058vsv.11 for ; Wed, 29 Mar 2023 04:02:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680087721; x=1682679721; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8fmDfQVJfo3Dbc0OAnvSbRRSopHfZFG1UGWWdaJsK2s=; b=ZO3iFB4xYh2NzSPw1AS8F2T2SbQX0nTlUyf7LRqt9eDLSeypM18wXKxt0MoZXQQSlX kpmvPpB2CBE6pcTEvyYOVeiwJcSUOLObZpzz5dyShkcRfafvzB6EaXnDUfkPPm3zRIKd I3Hs77wL22HTWYu7oFClxPN4gsFB/5OYQqU8vOSa22MNN1nFOrC/MS1j/An79APsvkmx DcDj8n7VYVXKS2Eb3fMzi0p8BlzlaOmFWKz7vvmBddgmBxcdzibazoCNw7zcDUavG5vf LHXqd0l8ZyN9A4ePzLOF++4iPBQ5Tkp/KU1e5vSJjcxkUWIzkW6H6Zh/BTH9UQK8hcZe s0Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680087721; x=1682679721; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8fmDfQVJfo3Dbc0OAnvSbRRSopHfZFG1UGWWdaJsK2s=; b=Pf2KzNPMXK0Kq3XYoXUYjJj1dWkbu7twKMxT0YuJQQMQ1zTdgM81/qdNqomjDn/97E xLqewI8YOKtStd406jueN7ISuyL5FZh+rgdIdLo0HlwfmtrmdTmQ4X/4x28XWAInwpVu sZpQiu4ttYEY4HHCu2myMsbAXQAnVsYzVIVDfK8rTm9/8pfC2COzG/XXc0RFJfDosDUa bsDh8EecdymyWfSgVA3gA4G/DN4fRUmvVf4mBMuayufjzZka5NccLgpp8K3hHlc4qWfb Xf687sk14/vIXjvl7nOds9Q23TSArMxOFRTRF1PbUU24Oy75E2/GuSlYUbxTwJfMtx7u CqlQ== X-Gm-Message-State: AAQBX9c4/fKBqxPmb0Frs5oW7S5frJN4TLBrRGPUOcKpeYXqyCf6XkK+ t+vfan+V1FglPrEZQ1VAMdqbSerQcBwang0lm6s= X-Google-Smtp-Source: AKy350Z9AngSGx2tZHMKsT09PVb7YjVyBH/2UWGC6pWWQWGbZANpvUBkoWnIoqSDdr8SW6mThUUdxGlILjDElN0/NMc= X-Received: by 2002:a05:6102:440b:b0:421:c4a3:b607 with SMTP id df11-20020a056102440b00b00421c4a3b607mr1512346vsb.3.1680087721395; Wed, 29 Mar 2023 04:02:01 -0700 (PDT) MIME-Version: 1.0 References: <8bbe91fa-9f32-e2c6-91b9-e982d25042ed@bastelstu.be> <09A79162-3FB0-4443-9654-CCECE0B9865A@cschneid.com> In-Reply-To: <09A79162-3FB0-4443-9654-CCECE0B9865A@cschneid.com> Date: Wed, 29 Mar 2023 14:01:44 +0300 Message-ID: To: Christian Schneider Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [IDEA] allow extending enum From: rokas.sleinius@gmail.com (=?UTF-8?Q?Rokas_=C5=A0leinius?=) Hi! There's a hypothetical (based on a similar real world problem that I am facing) example for the use of extending enums in the OP. And I don't suppose Tim was arguing for not allowing enum extendability, but rather contributing a real world example where users who were having some totally legal fun hacking around with internal PHP code would break said internal PHP code. Which may or may not be a big deal from my uneducated point of view, just saying :) And all could be prevented just by adding a `final` statement to the definition of `IntervalBoundary`. On Wed, 29 Mar 2023 at 13:42, Christian Schneider w= rote: > > Am 29.03.2023 um 11:55 schrieb Tim D=C3=BCsterhus : > > On 3/29/23 11:42, Sebastian Bergmann wrote: > >> Am 29.03.2023 um 11:31 schrieb Rokas =C5=A0leinius: > >>> I wouldn't say removing the final attribute from enums actually "brea= ks" any functionality. > >> I am with Marco on this: removing the "finality" from enum would be a > >> major backward compatiblity break as it breaks a fundamental assumptio= n > >> about enums. > > > > And to give a specific example from PHP 8.3: As part of the Randomizer = additions RFC (https://wiki.php.net/rfc/randomizer_additions), PHP 8.3 got = its first "natively included" enum (\Random\IntervalBoundary). This enum wo= rks together with the new Randomizer::getFloat() method to specify if the g= iven min and max value may be returned or not. > > > > The Randomizer::getFloat() method internally includes switch statement = that chooses the implementation based on the IntervalBoundary value given. > > > > If a user would be able to extend the IntervalBoundary enum, the method= would not be able to make sense of it. > > > > The IntervalBoundary enum completely enumerates all four possible combi= nations for the two possible states for each of the two boundaries (2*2 =3D= 4). By definition there is no other valid value. > > I do understand the reason behind making Enums final and your example ill= ustrates the point very well. > > I still have a question I already asked in a different context: If there = ever is the need to add a case to an Enum, was there any thought put into m= aking this possible? Or is this categorically ruled out when using Enums? > > Let=E2=80=99s look at a very, very hypothetical example: Imagine a Random= izer is much, much slower for certain boundaries and it is decided that som= e programs do not care about Closed/Open but instead care more about speed.= So they would want to use something like IntervalBoundary::Fastest. > > As far as I understand such an addition would *never* be possible, right?= This means people defining Enums have to be very very certain that no one = will ever want another value, right? > > Regards, > - Chris > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >