Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118091 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48167 invoked from network); 24 Jun 2022 14:48:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jun 2022 14:48:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F0CE1804F8 for ; Fri, 24 Jun 2022 09:38:05 -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-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 ; Fri, 24 Jun 2022 09:38:04 -0700 (PDT) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-3137316bb69so29896317b3.10 for ; Fri, 24 Jun 2022 09:38:04 -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=FcsnIRYoUv+0+H61vcA2S8GjhemtG5QX/SzYVPyrAIw=; b=DTtyB9AGTxflRn8iFAOplhZmMs9aD+C/FgdyEocQNA2zP+6NYmS6gcwEkfgfKdRkEx z/bIdNsettk9WjJEjLHrRzk+YsbF+IL35ysTmRoOEDv9z7IqkCq5Gg6W36vWxvDHX01z LUlFBFD5Sr3LIBfCdBhYRiRZmqebRaC20pcimw1kSAyahNWcNIyZ8F8aqUwmawa0T71n Ms3oH5WC8JQCW9Tr8BODHFl4qe1hkPQYWyH8qdBA6SpjPaVxNZIQmlMV5sURWBw3T3a/ 9g3EWfdrnCx6eQy4AFx0q2Ug+ueujFpIKuWAWiTepEcGGdIljUIh8RoGEqwMPCWlgQsM ppXw== 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=FcsnIRYoUv+0+H61vcA2S8GjhemtG5QX/SzYVPyrAIw=; b=3RbOx43yh0ml32yicYQe25RefVT212qzZq1V0omyJ59B3dP+O0YnAO8r/9NWw+qldh XU7Ctji30IyKeg5ih0HqEQay3BuAja+hQHsEif2WKn8d38ua7HwUwHyUjYsKJWfcJLWm zV9VfnpFbyuj45e3eLQdJwgkEGFoZd7S7RxItxWVZo1pD/AjGRG10kGkeRa9P8ZzBF9r j1xqr6jojfVhOYjbsf1a9Ck7xK11tn7foQDJiLzQVpBDKjzpz9/MG4sIgIW790QPhBOA 3r89nvJsT1xmpmJjxP49X4q0V6SgC/CAUQbUJQirjs13Gbyn2RHbPfalSnn+ilS9f3R+ IpjA== X-Gm-Message-State: AJIora//9Ly5xl2t0/XASu9XBeOL269OFFDNjbSz1LAP4aiucrF6pgYe qamWT8TYkc25sJ88zbKyQxQiyvFtwgezn/VWfZdOyIQ5CV6tBw== X-Google-Smtp-Source: AGRyM1v6CD5cdsRiH7285dg2HxtCF2Y2VFRqA51s+bt0/AeoskcTevAlnRvJfkUHVBAeKGMxZZ5vBRk/yJ5GUp0DPJo= X-Received: by 2002:a0d:e0c6:0:b0:317:9602:55d1 with SMTP id j189-20020a0de0c6000000b00317960255d1mr17380512ywe.2.1656088684121; Fri, 24 Jun 2022 09:38:04 -0700 (PDT) MIME-Version: 1.0 References: <9C11261B-B9D0-4342-81EB-60276B3036E5@php.net> In-Reply-To: Date: Fri, 24 Jun 2022 18:37:52 +0200 Message-ID: To: Guilliam Xavier , Rowan Collins Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000bbd26e05e2343143" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Auto-implement Stringable for string backed enums From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000bbd26e05e2343143 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Guilliam, > > There are also cases where using "->value" is just not possible. I > mention > > attributes in the RFC, > > which also mentions > https://wiki.php.net/rfc/fetch_property_in_const_expressions (but with > "For people that use non-strict mode, this extra =E2=80=9C->value=E2=80= =9D is > boilerplate that they'd better remove") > Absolutely. Providing a nice and expressive syntax is critical. We added e.g. short closures, constructor property promotion, etc. all because we care to not write ugly code. With the "Fetch properties of enums in const expressions" RFC, we soon might be able to reference values in enums with this syntax: #[MyAttr(MyEnum::Case->value)] I understand why we're considering this and this might be only me, but I find this ugly. The same happens when coding: take_string($enum->value) This ugliness is part of the problem I'd like to solve. Rowan's proposals about sets could solve this in a very nice way , but we're not there yet. I can wait though. > Symfony YAML has a `!php/const X` feature, which also works when X is > an Enum::CASE; how about a `!php/enum_value` feature? > I submitted something similar today at https://github.com/symfony/symfony/pull/46771 Otherwise, I also like Rowan's suggestion of implementing "internal > cast handlers", so that non-strict users could call e.g. > I had a look at gmp for example: cast handlers don't work when calling a function. They do work when explicit casting and when doing loose comparisons, but they don't when calling functions (or returning from one.) I don't know the underlying reason for that behavior but it looks consistent. Unfortunately that idea looks like a dead end. In any case, several people requested that it should require to be > *opted-in* explicitly; but then [for solutions other than "allowing > user-land to implement Stringable"] we probably also need a way to > test whether a BackedEnum [instance] is "coercible"? > I don't have a solution that meets all the requirements that ppl expressed so far. If I could get back in time, I would enable that missing casting rule I described for gmp in non-strict mode, and I would implement it on backed enums from the start. I'm now considering withdrawing the RFC because I don't see a way forward that could be consensual enough. If other ppl share my concerns and have a proposal, please let us know. Nicolas --000000000000bbd26e05e2343143--