Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117457 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60700 invoked from network); 30 Mar 2022 12:55:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Mar 2022 12:55:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0170C1804D0 for ; Wed, 30 Mar 2022 07:23:50 -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,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 ; Wed, 30 Mar 2022 07:23:49 -0700 (PDT) Received: by mail-ej1-f46.google.com with SMTP id qa43so41833359ejc.12 for ; Wed, 30 Mar 2022 07:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V6ZTww1JILQ7gT5lluRyGKBPmCccalmJcPzCzK6xqDU=; b=ENC40O/Gy5lqYbMlTh7x6+EN/JembepdgHrpjDO9htzFH6m9IDHmzWj5G8VmQ4nvkZ REdseblZae0ayX2eqnktgxHR8gEqrK7Jnee//6NxF+iVBFljT+01VtOwWjby1rDH3h7d aM14aKd82tXxo6GaphLzDPZ7JvZeczIwGorfo2rXTLC5xeVh7smECJFrSdvMYYQolx89 q32mdh3c81LjdIlaC+FrFS3EOrT6DKqn01rtpJ0OtyIZEK0BweIx33HQ+hYwbUS2DuXh 4TW0lWsnuWVb5KooqZiFO/aVVvmoy4Q/ujomAWPXBY76Z8WIUwuUb+N+krnlqRGeuWkJ sYCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V6ZTww1JILQ7gT5lluRyGKBPmCccalmJcPzCzK6xqDU=; b=UlFfIoNdAj3VZS78v41e/COUufByGvrIjxgYPd9N609gxI4x5fm+IRaLb0W4vNk+2P t3AvP8U8O08z1KixTtHb5d6I9etDFNGmLOTzxCIJb/Q09ldGtUQRRlMwixltjwKPPw1e Ip80Kim2O50Ka1hXpRiyMCuitGzaLNoJFCXangf733i9ONWWFikgMOiek01DEbW7bX9i P/WKdSi6yGWw6TsNs0UyFQHqgGktDJYUKwgZ+12T+4+6fGjeFwic1xx8oPMG+huVxpwq OWN4KO0qIPWn9u31+ie2QjXuJK3ZIyNTDUw99aXEnbrPwwVi26fgEP62LtQleYxHhPhY OAfw== X-Gm-Message-State: AOAM531wnxfOGD7kpK972pmfed5BrcAkpEyALzwCKY133NMy6Mca7sj8 pdHiqYiACqTcbW3VgKoEcqRIJeDeJXTet41g9dG07k5b X-Google-Smtp-Source: ABdhPJxyNcngSH3Kzg/gn4kLrjMcV6PPdvOmfqZ6/RtL9cLslrBdH30g/lCJv7mjM2MVYj2EQ66xvJWIdCZ3b5CiUt0= X-Received: by 2002:a17:907:ea1:b0:6df:7900:e4de with SMTP id ho33-20020a1709070ea100b006df7900e4demr40245953ejc.26.1648650227971; Wed, 30 Mar 2022 07:23:47 -0700 (PDT) MIME-Version: 1.0 References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> In-Reply-To: Date: Wed, 30 Mar 2022 08:23:36 -0600 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: Guilliam Xavier , php internals Content-Type: multipart/alternative; boundary="000000000000327bb705db704bac" Subject: Re: [PHP-DEV] Typed constants revisited From: mbniebergall@gmail.com (Mark Niebergall) --000000000000327bb705db704bac Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Alex, On Wed, Mar 30, 2022 at 7:47 AM Alexandru P=C4=83tr=C4=83nescu wrote: > Hey Mark, > > On Wed, Mar 30, 2022 at 4:01 PM Mark Niebergall > wrote: > >> Alex, >> >> On Tue, Mar 29, 2022 at 10:35 PM Alexandru P=C4=83tr=C4=83nescu >> wrote: >> >>> Hey Mark, >>> >>> >>> On Wed, Mar 30, 2022 at 6:03 AM Mark Niebergall >>> wrote: >>> >>>> >>>> I have updated the RFC https://wiki.php.net/rfc/typed_class_constants >>>> with >>>> more details and examples from this thread, and updated the RFC status >>>> to >>>> Under Discussion. Hopefully the updated RFC helps answer questions and >>>> clarifies what the proposal includes. >>>> >>> >>> Thanks for the RFC and the drive here. >>> I personally see the benefit and I think it would be a nice addition. >>> >>> I think you should also update the "Supported types" section. >>> Starting with enums, constants can also be objects. Once a good >>> technical solution is found, any object would be supported probably >>> https://wiki.php.net/rfc/new_in_initializers#future_scope >>> I think that only void, never and callable types should not be >>> supported, just like on properties. >>> >>> >> I have updated the "Supported types" to list out all types that are >> supported and which types are not supported. >> >> Constants cannot be objects since objects are mutable, so typed constant= s >> will not be allowed to be an enum (which is technically an object). A ty= ped >> constant _may_ be an enum value though, so the following example will be >> valid: >> >> ``` >> enum Fruit >> { >> case Apple; >> case Banana; >> } >> >> class Colors >> { >> protected const string RED =3D Fruit::Apple; >> protected const string YELLOW =3D Fruit::Banana; >> } >> ``` >> > > Actually, Fruit::Apple is an enum instance and that is an object that is > of Fruit enum type (Fruit class). > You can check this as it's already possible in PHP 8.1, even if it's not > yet possible to have them with type: https://3v4l.org/f4WIC > > What you are referring to as enum value is actually a backed value for an > enum instance. > If you would define the enum as > ``` > enum Fruit: string > { > case Apple =3D 'apple'; > case Banana =3D 'banana'; > } > ``` > You could obtain the value with Fruit::Apple->value. But I'm not > referring to this. > > So going back to the topic I mentioned, a constant can right now be an > object. > It can be only an enum instance for now but I believe that in the near > future we will be able to have any object there. > Ah yes, you are correct, my mistake. I will need to make some more updates to the RFC page to address that. > > Also, self and parent would make sense for valid typed constants, just > like they do work on properties. > I'll add examples and an item about this as well. > > Regards, > Alex > > >> >>> >>>> Of note is the "Inheritance and variance" section, which details uses >>>> with >>>> abstracts and interfaces, plus the "Constant values" section which >>>> includes >>>> details about errors. >>>> >>>> >>>> > >>>> > -- >>>> > Guilliam Xavier >>>> > >>>> >>> >>> Thanks, >>> Alex >>> >> --000000000000327bb705db704bac--