Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118076 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47961 invoked from network); 23 Jun 2022 14:01:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jun 2022 14:01:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1D339180504 for ; Thu, 23 Jun 2022 08:51: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, 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-f176.google.com (mail-yb1-f176.google.com [209.85.219.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 ; Thu, 23 Jun 2022 08:51:04 -0700 (PDT) Received: by mail-yb1-f176.google.com with SMTP id o79so463740ybc.4 for ; Thu, 23 Jun 2022 08:51: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:content-transfer-encoding; bh=UKO+8LrYjLCfMKzkkI8SHosod+m7PMyxt8aYRmTXjSw=; b=WeC4eDcAAvLNCDLGQjnU6mot3yPKTZxTznnwFybzmxgrqOHFhtlswfIPTdI9dQZLNU h9QglfM1cQ6KxusaQ/OoYhXImz6zpTl4CEh5QhE59lpZsF2Lpf3kgPTTb59/pkTiKrRd LIQiqlMXQbuB0v4RAouM1VxS7knk7HHYICryqmPyIlTxNkuAFDV0eEZ9zSqvh6w+pNpT 3J2XSYpXsNfyADkxZQwI+dfgbosti2hpuvF4fXIyZP6NZSRC7Xx1wdbT85BDZu7XaMga 8baHmE/YA1kyFofTnarx2pDOLUSAlFUHM1yNplMIuAmzuRUxkzf4YWAo1HBkcUZombc9 m0pw== 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:content-transfer-encoding; bh=UKO+8LrYjLCfMKzkkI8SHosod+m7PMyxt8aYRmTXjSw=; b=nOvG523a1LZ8I5Mq79LPFvZ6+RwzUslfBInNMHTzydBCcftspIXmQik0mqWZB7e0QO oM/TgyNdfHJfAkKQheqMs+wqQca5W5PPbf23INwBcKSRGyjr0ZBfskg8Sd/9X6MO94ei xB79ebItJzNr1Hx6jWDZ+kG0MSW5O99kSkiDLHSVTlY6QH63DsrlTRRykQg7K4Zc+QW7 SZKE4RrftZwVLYGEyAxU08Jy/UXgSjbICxoTVHNjGuh136/vAGHtj9dEXBLqhRxbCJCu mghkqErfkLkMfMdFa6Iqo7PjMeUk5pryQNOBp73tiHzeYkuC8iZs11hGFpqG+/9XeoJo aDlw== X-Gm-Message-State: AJIora9QvmQO0WEZrkdprYzWj1GNOq3NW03hMwqdfWPHlhb/LYi/10KR FFB4/tu9+L5dx8WVkMFxnA84FK3gdLRlv4ETZw== X-Google-Smtp-Source: AGRyM1s4iwoLfm9hf4g0v8yUEo9IjsbQzQoEvGSdsDiHgQGuC+rZ3FoFizw0fsrXwQn1K6nIPwMNUSB7xC/FSei/320= X-Received: by 2002:a25:bdc9:0:b0:668:3d05:e009 with SMTP id g9-20020a25bdc9000000b006683d05e009mr10556936ybk.402.1655999464051; Thu, 23 Jun 2022 08:51:04 -0700 (PDT) MIME-Version: 1.0 References: <9C11261B-B9D0-4342-81EB-60276B3036E5@php.net> In-Reply-To: Date: Thu, 23 Jun 2022 17:50:52 +0200 Message-ID: To: Nicolas Grekas Cc: Rowan Tommins , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Auto-implement Stringable for string backed enums From: guilliam.xavier@gmail.com (Guilliam Xavier) Hi Nicolas, thanks for the RFC, > There are also cases where using "->value" is just not possible. I mentio= n > 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") > but we also have a case in Symfony where defining > service definitions in yaml doesn't work with enums because there is no w= ay > to express the "->value" part. Symfony YAML has a `!php/const X` feature, which also works when X is an Enum::CASE; how about a `!php/enum_value` feature? Otherwise, I also like Rowan's suggestion of implementing "internal cast handlers", so that non-strict users could call e.g. `takes_int(IntEnum::CASE)` as well as `takes_string(StringEnum::CASE)`; but what about `takes_string(IntEnum::CASE)`, and `takes_Stringable(StringEnum::CASE)`? 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"? Regards, --=20 Guilliam Xavier