Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118057 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43817 invoked from network); 22 Jun 2022 15:32:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jun 2022 15:32:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E413A1804F8 for ; Wed, 22 Jun 2022 10:22:26 -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=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,FREEMAIL_REPLY, 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-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 ; Wed, 22 Jun 2022 10:22:26 -0700 (PDT) Received: by mail-pg1-f173.google.com with SMTP id e63so15176111pgc.5 for ; Wed, 22 Jun 2022 10:22:26 -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; bh=eDZFmQeXVk2H6gliRcTscwTkithNg/xzge/NshQ8nhg=; b=fEBGaOmEMbTAZQ1s21vXKwKKiWMNDx/4yldypReC8tcJEzLpxBfK+vGnvrK9FlZ8dv 1SHH7OB5Ldgl+Hhq4vgzkCU2cYt9VyXp9YykRJVLgSZCe4T2jXvv1s3OcHsYzyhNBUXk TPUHsO1ccAK6gVJ9WpRScoo/yQvw45mb4Z0aBc7bxz8nFZqMlKXJcjBKYOk5OkW4y0Om EPOhbhGUNSZ0nEwaXsY87fZqIFkuc570FikSQTEemM142JxdC4BZAvgdYGCFwjg+Z4PJ ueZCx9RYd9aQxNKUIlfcJYMmuprNwWdgv3y5i3Hhm2Xyge0llQQfAipQlZ6bBjAq6CsD Eq8g== 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; bh=eDZFmQeXVk2H6gliRcTscwTkithNg/xzge/NshQ8nhg=; b=LsD6xrRZXSyO++kjQLMZ54VfTlFv/Hgi4R7GZGxqIK/tv/6fYAEhH38tolxc4kG8bP Jdu1AKcgLMqICnBEgW8lnZhYYbiSYkvpux49uY+XEaYrp8w2X1zJut66q8JMAhczNIGs Ne3/OFR38P4/iGSDfvOpA6awu4acL3LXaQJK5fzvY6ZyjnwkylI1LvDRcRfb126hstoh CordzBhfHw0QREO27PeyRAFqg8/wUistl9YodMwJcgdtr3S4Q0uZbHFijoSusRfTKOxH ozfC61Vh4qwxjiDCJisvlvU9xz0Gr9gjDu6O55BsLVmz2Gi5Dkq6BGz6j7r8xvI2fv/T kitg== X-Gm-Message-State: AJIora+RHPUZzdA3lmIsPoaCpfIVuLlTk/LnvqqbZNvIJ2JJYnLLWlS9 Ponx7uX3EoLkZDo1Se4lMDfJM9xOs1Kxkcg7anV7EYdEqFA= X-Google-Smtp-Source: AGRyM1uR9AruKW0bvk+R8atSpYK3JohRV/cj5I8ODRH71vMo/2+6v2CCxRtbVmh/dnDIUJUSjk6abT6f+XB0z362LlY= X-Received: by 2002:a05:6a00:15c3:b0:525:2db4:2a3f with SMTP id o3-20020a056a0015c300b005252db42a3fmr13541852pfu.23.1655918545487; Wed, 22 Jun 2022 10:22:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 22 Jun 2022 18:22:13 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000ae4cca05e20c946d" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Auto-implement Stringable for string backed enums From: rowan.collins@gmail.com (Rowan Tommins) --000000000000ae4cca05e20c946d Content-Type: text/plain; charset="UTF-8" On Tue, 21 Jun 2022 at 23:47, Nicolas Grekas wrote: > Hi everyone! > > I'd like to open a discussion on this RFC, to auto-implement Stringable for > string-backed enums: > https://wiki.php.net/rfc/auto-implement_stringable_for_string_backed_enums > Hi Nicolas, Like others, I'm lukewarm on this - but then I've always been lukewarm on both Backed Enums and __toString For me, the big value of an enum is as a value that is never equal to anything but itself, so the idea of MyEnum::Foo == 'foo' evaluating to true feels instinctively wrong to me. Meanwhile on the string side, I feel like most objects have more than one string representation, so "blessing" one makes little sense. Taking the example of permissions given in the PR discussion, what if you need to pass these same permissions to two different libraries, which have different format requirements? However, we DO have backed enums, and people clearly want to use them for this scenario, so I'm tentatively OK with allowing them to do so, since I can just use a non-backed enum to get my preferred "style". Derick raises a good point about it not working for int-backed enums, though. What if, rather than implementing __toString() as such, we implemented internal cast handlers for either string or int, depending on the backing value? (Other internal objects do have this ability, e.g. GMP and SimpleXMLElement) Regards, -- Rowan Tommins [IMSoP] --000000000000ae4cca05e20c946d--