Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117454 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54829 invoked from network); 30 Mar 2022 12:19:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Mar 2022 12:19:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 647521804E3 for ; Wed, 30 Mar 2022 06:47:58 -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_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-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 06:47:57 -0700 (PDT) Received: by mail-ed1-f52.google.com with SMTP id g20so24482167edw.6 for ; Wed, 30 Mar 2022 06:47:57 -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=W71B8e884pV4xoQqM1/IYhJE6i95sWWFmgM4toYX+o0=; b=KRk0wdTkb0kG21WiKR/R1rDHwQ3GmlJlrXrhz8Rg3gRO8zrTJR4PrYwkzjWAu9kqh9 SBZm0FJ6ioaAbgs6P7EngRREW55IV66NfnJzqcFFfRF7MzymjaM0Y3e1JlZMXV8iw3ze xyNKu4gFuDzTphrVrAWyZ6DT2qO6BHI/3MdO8n0mEoeF1s76+Tps3gP7x1Iw7hFOBzHN ceqOASJMil5jGJ/0fMXggdlHmRNDnmHsBk7grcu4kXWZvOBXgXiij/Otn+1mn/O17skS /LA0XvLyngwKnsK6hc3U333VkcTNOHq7gDcED+6Ag5TCaZoJmyq1Zb/FW+YF8okZHhQ6 oBvA== 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=W71B8e884pV4xoQqM1/IYhJE6i95sWWFmgM4toYX+o0=; b=pxSj5EFjf488GxpaSTjm+brbIRdOrkvzT+MEdWm64LVAQoik2u/ciYu/Xd/aUhRtgk GySLnZLsV+RMnZJWFP8QSxyNyvT5YQq4zuw0pDlr/uGVmayk+P5rze6U+N/vBItIp9pL om7t0sycrm24vTZLIfWy7KJ+KKpLT7PmxakGzmjh3pajh4XmYzP6X/ORCjTjSixTr4tI uQY+hyaLSix0HIi+JCBvu9COO5jR8VeedU3/UZqe3p2jFUY2kPBn9e4nPCsKYLDpS+GG ZlgYX8g4KsKs5iQ1aPx3s5SrPE5+0vCxHNanFPCk5ncSXbGIl93s43+ew6iqk/r344a1 UVyQ== X-Gm-Message-State: AOAM5332o087D1e0KR6JXoY2m3mQje5vVbnlUdmfCihDhNK8k3bIA6BV F4wPEng0r4aG+iHzXhhIMckC1iXR1FSw3RlkoXNpI2hHtoL50w== X-Google-Smtp-Source: ABdhPJxF2LoyypCyKcFgjs5BFhE0lgcFwG3GybnmUrva8RftK9ezTIk6/H7itpCIbl4D9NsMXCgRW8Jm8soFBgP9Msg= X-Received: by 2002:a05:6402:26d3:b0:418:d202:d5dc with SMTP id x19-20020a05640226d300b00418d202d5dcmr10693507edd.138.1648648076432; Wed, 30 Mar 2022 06:47:56 -0700 (PDT) MIME-Version: 1.0 References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> In-Reply-To: Date: Wed, 30 Mar 2022 16:47:40 +0300 Message-ID: To: Mark Niebergall Cc: Guilliam Xavier , php internals Content-Type: multipart/alternative; boundary="000000000000f499c805db6fca45" Subject: Re: [PHP-DEV] Typed constants revisited From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --000000000000f499c805db6fca45 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 technica= l >> 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 constants > will not be allowed to be an enum (which is technically an object). A typ= ed > 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. Also, self and parent would make sense for valid typed constants, just like they do work on properties. 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 >> > --000000000000f499c805db6fca45--