Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117455 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56251 invoked from network); 30 Mar 2022 12:22:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Mar 2022 12:22:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E301B180539 for ; Wed, 30 Mar 2022 06:50:40 -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-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (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:50:40 -0700 (PDT) Received: by mail-yb1-f169.google.com with SMTP id v35so36870431ybi.10 for ; Wed, 30 Mar 2022 06:50:40 -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=E+zeFl1LJAfk+YU16ddJRaf9YCcr5ShKD9zJMws+jP0=; b=aAalLs+DD9fBcsOJ7wQZaTmhPxL7sLwHZuDpaygH9RBTi20PkNXQrH7z1UkFBGNyOu TKvuai+8CZ35ut8IeN0/t+ooLIewmspC0bV4ItBrChj/FRDddBek6VTtdd7tJLwVIrF5 jijt7hk7i1R9dYYwLseuIxKoZhdPBRdZxhWeFXyT9T1cNZbiY5KkGIz2msy3KQtZhPoU vInznbRa6o8WA+2k7WscYUbrL+6a/YStLJNlvRqy+Kz7GDQ5x8P+NXbWM0oQsHUMscsm LtVa2VhcLRFvmeF7Wn/6rSRyANx7Frulv3/uMGXbVsA9uyTprqTwImZeoSatvqoANw3y HHlw== 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=E+zeFl1LJAfk+YU16ddJRaf9YCcr5ShKD9zJMws+jP0=; b=yt0j1i06Dl9KJw3kUfHaJ3hKWp1turWVlNsur7ovmLMUrxi3mWxCqnBd8lg6GvfLD2 aif0fz/9Irx/OubByHskaG1hTWRkwgcqf4sf0kS2ChJK5ZirnChIhjDtMGEBDo2Zu15h 5Gq362gxjAOOsoBsy6RB3RnXOwOXIQERAMLo9EU5aaGfmu8Ho12JnGuqVGQwvzNQidXB 9FFQZApSpY8ngblXX8hs3oc80IzD75OKNXhHZ1zKv2tF25CuAfAR7qj192JvnK5246E+ /GtkiL6Jnj2b3V7z1kGX0WO2EVemdkdhFZkKnvBoMRUFYc/LLBS7ZYKceLYYIO3YmuL7 2BSg== X-Gm-Message-State: AOAM532ZgakxoIi2Bsu9Dh72Ee0oWybiMXhZCvRKREPByLrW3oujnaza 5MXIMeyWS1dIDYBIruNFmrFdBEy2peTIl/sA1g== X-Google-Smtp-Source: ABdhPJyVo+i2j6fknHvEn8/TFQ3sgA30/Ghan+Y+chd8NlPAyZZLQIojbEGwYCQFE6GlVff1bsgVzemzsi1mMI3SACk= X-Received: by 2002:a25:dd87:0:b0:628:e822:bd with SMTP id u129-20020a25dd87000000b00628e82200bdmr30481816ybg.505.1648648240242; Wed, 30 Mar 2022 06:50:40 -0700 (PDT) MIME-Version: 1.0 References: <76c399cb-fb29-4583-a212-8eb69740c96b@www.fastmail.com> In-Reply-To: Date: Wed, 30 Mar 2022 15:50:29 +0200 Message-ID: To: Mark Niebergall Cc: php internals Content-Type: multipart/alternative; boundary="000000000000b826c905db6fd473" Subject: Re: [PHP-DEV] Typed constants revisited From: guilliam.xavier@gmail.com (Guilliam Xavier) --000000000000b826c905db6fd473 Content-Type: text/plain; charset="UTF-8" Hi Mark, 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 (I assume that you talked with the original author) -- not sure if you should have started a new thread with the "[RFC]" tag in the subject? > 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. > A few comments, by subsection: - **Supported types**: This corresponds to the types currently allowed for const values (as well as unions thereof) except it [still] doesn't mention enums (which internally are classes implementing the `UnitEnum` interface, and whose values are ultimately of `object` type) although currently allowed. It also doesn't mention `mixed` (used later in examples). - **Strict and coercive typing modes**: I didn't understand it on first read; I had to read the later "Constant values" section and compare both with https://wiki.php.net/rfc/typed_properties_v2#strict_and_coercive_typing_modes and https://wiki.php.net/rfc/typed_properties_v2#default_values - **Inheritance and variance**: Several occurrences of "Class constants" should probably be "*Typed* class constants". Also, I still think that `protected bool $isExtinct` is *not* a good parallel to `public const bool CAN_FLY` (see my previous message). - **Constant values**: You should probably remove the `iterable` example now [and maybe add an `enum` one]. > 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 typed > 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 = Fruit::Apple; > protected const string YELLOW = Fruit::Banana; > } > ``` > This is incorrect, `Fruit::Apple` is of type `Fruit` (ultimately `object`), not `string`. But it is *not* mutable, and *is* allowed as a const value currently. Besides, I realized that the RFC is [only] for *class* constants; what about *namespaced (and global)* constants? Regards, -- Guilliam Xavier --000000000000b826c905db6fd473--