Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113587 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47494 invoked from network); 17 Mar 2021 08:43:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Mar 2021 08:43:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 91A191804B8 for ; Wed, 17 Mar 2021 01:36:59 -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 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f171.google.com (mail-yb1-f171.google.com [209.85.219.171]) (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, 17 Mar 2021 01:36:59 -0700 (PDT) Received: by mail-yb1-f171.google.com with SMTP id h82so39618918ybc.13 for ; Wed, 17 Mar 2021 01:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Lm7PJ5QqPuK5mKplV9WkCOKVAp5379h6vxo9FtTch4E=; b=E4U2o6vskOSdz4bntFVZzsD2B6Up2sO0cAzbRTccmQqjJyNAOdmbQfSprte54B3rB4 uTdxk3u8EjSBl8lTU21VMsuzzS5+oQmFs2OcFntvF/OzW2t+onrULIUobhwpNiEOriRh Y/xM7/bRaVnQW3jN/ckwSgwKlEO/LctVU47NnlFZjp91II/Rpuy3YbujhNrYrzrwO1xy UTKSyegLdIkhTirZGMt8aYK5HGNi7LusVrul1ecSpIVG8dFe1yHZ5Du3+ej/6Q3Cp83o g5hJ+ohoME2gM4X19J9HDqtJjPhioWeSPZF+P5ds+cLZyTAqqfk9gpeze8LE/mnnYMNV SYmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Lm7PJ5QqPuK5mKplV9WkCOKVAp5379h6vxo9FtTch4E=; b=Fi+BdQM3PO2oyykpB54NTc/j95FYtn897+Fd9F88DefvF6RZTFaNVzvfrdbd9qTT3x Ydo8CWMU+Jp8z+n2xydzV0W95gksByi+I2dM9h7zny4kzXanbzz8XZ2wtXp0iND2LDWq XM1rG093ilrVM+S5mhgqVUEez1ApSVxv6/P6cN2UOn02+GDvhiTpn8zc5MEcXLzgiBmZ FF6Ntf0bOxvfSewa4EPff5IfONptsQVM0qLvhO8VeW+qQkxtjcCaior6N0FeA4SKRaUs SbQu0QrhThRpDm2BlDB99AO8nbFN7WJHbfhlPGljH72zrcmG3IXOEVl+9z6Gl4i58QSJ sTmg== X-Gm-Message-State: AOAM533FA5q01mOuxCi5kEE0RgkR2mL8yz88/pqR7YiiN1LiUU4U1zeh ikd3eBXGeBSEu534hmIHtHN2ZVL3/beE7PPFramV118C2DM= X-Google-Smtp-Source: ABdhPJxLTBbSK/Eue2zc62I7quMfCjoxtKkU49qUVX4B54G+VaEdjeRT5rk6Z90xwd+aKldx7i30E+uhM8e75EN51ms= X-Received: by 2002:a25:74cb:: with SMTP id p194mr3210090ybc.347.1615970216558; Wed, 17 Mar 2021 01:36:56 -0700 (PDT) MIME-Version: 1.0 References: <2ff5377c-3718-feb1-ba20-96df47357414@mabe.berlin> <9f234d2a-7875-2871-6726-e7b8175099f3@mabe.berlin> In-Reply-To: <9f234d2a-7875-2871-6726-e7b8175099f3@mabe.berlin> Date: Wed, 17 Mar 2021 09:36:44 +0100 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Inconsistency in enumerations RFC From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Marc > >> I think it would > >> be much clearer if there would be two different interfaces like: > >> ``` interface IntEnum extends UnitEnum { public int $value; public > >> static function from(int$value): static; public static function > >> tryFrom(int$value): ?static; } > >> interface StringEnum extends UnitEnum { public string $value; public > >> static function from(string $value): static; public static function > >> tryFrom(string $value): ?static; } ``` or else the above example should > >> return a NULL or even case matching the string representation instead of > >> TypeError as it matches the defined argument types. > > I guess the interface would be more accurate. I'm not sure if that's a > > huge win or just unnecessarily bloats the API. I think using > > BackedEnum as a type hint should be relatively rare in practice. > > Optimally we could add an associated type or generic type to > > BackedEnum but that's currently not possible. > > > I think it would be at least be helpful for example on mapping an > enumeration from database to PHP as it's possible with doctrine types > and probably also for static analyzers without the need to special case > enumeration objects. Can you provide a concrete example where the current interface is inadequate? I can't imagine a situation where you'd want to accept all integer BackedEnums but string BackedEnums. If we ever expand the types that backed enums accept the number of interfaces will grow linearly. > I also don't think one additional interface bloats up the API or waiting > for generics helps as nobody knows if this will ever be a thing in PHP. > > Would this actually require a follow-up RFC or could this be done as a > small implementation detail change ? Historically, things like this have been done before if nobody objects. But that seems unjustified at this point given the lack of concrete reasoning. Ilija