Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126700 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 0519F1A00BC for ; Mon, 10 Mar 2025 21:44:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741642930; bh=O8uwaYk9VvkSTvqdu4tiProY6GWIsYU9SfT/jIcJm9M=; h=References:In-Reply-To:From:Date:Subject:To:From; b=VLNnxhHBZPhl0HKm6Ee0ozSkGLmN05+6EKr04hSPiC9iAzi8olzMsWBtpJCD7M8Z9 2nvr8xf6W+m7nSd4shhcyC5Lvi11Yu4JmX2BI/vJ8DBoDMVPvnNdiVR6KgPMA2FqEm g8dez3s6eOLtnYWC2+vTF6Y7PqmYrQfREVXyIE3t8dWIXD8SyeMoUv1ZQkqBPLuNCR rV7muApPOnW9CY8W7LZpQRPM44Ws4NKcweloDlh/GIFhqUXSJdzpsiR8rcmqCQqua7 llmNCf6KYk7QJrvyCcQaaJNXDIwQbS+658dSY0WTZcenP2hhHvC8K/W2yvKZektqji Iq5bhB4P05OWg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CB68C180037 for ; Mon, 10 Mar 2025 21:42:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 10 Mar 2025 21:42:09 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6dd01781b56so54413196d6.0 for ; Mon, 10 Mar 2025 14:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741643083; x=1742247883; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=j32xKLPoCHrCUc2ernuBMztVcZ7WgFW0QwcvzFlB418=; b=Imsgpt2OylZV+6yX0VRVKwfloEf5XNLbiI8pkxAK1EoLX6UxuF+9Lm58Hbt4gYPf7g 6jEqlLM/t/E4tIdZD1onhFpeyqgwVaPnBLYUUxmT/vzL9cZrEIG1aELQK0/4ZUCpWpfF kq8WWqXLsDnOH5zWQ1bOn8E8Hlj5ikg+dG0ON6Jly76BMsQWPpquEVyZ5MbyQE03VLQm jmlRgNL+phVT8J5tRJxSqb+P1ISe9lpjR8v9NteJCHqn5on1lKt8bvis9hXDR1G8keGi d/+rcZZdGfQRDmqMNIpopMhGTcxgLWAF1fcppMthMKbgG02NxoMzCRYiuCCu7MbX/LOJ qwTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741643083; x=1742247883; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j32xKLPoCHrCUc2ernuBMztVcZ7WgFW0QwcvzFlB418=; b=iXfWaPLgw40pQ6PwKLThx1Oj/7FPwxLpvTaqadYLjw9NNT2GbFmbqN4Ptg8CAYfHdx fwPiWQMzD/gsD1ENQi/qqlHN0JPky47EuDdH7obnb+STJ/811cVs2wbIeVVP0QQ/Cigp K+1Hgth/AXg+ju7rSxtjDtijYq+yhLYusWXWWcJ6+mx+2Ztr5VZ++TW1BFX5/RLGH7yk 11pa6IDeO5VLBRqFjzobTdbJtNLFhTnf0/YoWX0FmAy8ZkYGwU1p+R3kiWYNWIg2uS2D khzoad5aLqEYAbGn8aftEOKwO/XFqHHiOnvYzLTKnOHkAbZAt9paB27b73SxMG7VP4B8 2RzA== X-Gm-Message-State: AOJu0YwvM5dipvlgR4YHQjREw++qUnFy5eaD7/cUr3BDyaPcoj5SZiuJ dmVAHz1wQUTZMNriyaX7NAggKGfuvorVGFDCzmiBeGBDejcshhEO8JjyBzEWNKreMZrRu1BdYb9 ylXF1B2HVjXqHQUCm+sQgiahH7DsVeXTpfWE= X-Gm-Gg: ASbGncuk1K9+33eSNfDNJIz5VGYK3QKNLDh+TAZoT1ERuUlMzb6lXglEdRXJQKorN0Q RXl1LodgVME7zlbBhcuCeHgt9Pum82HcLoGzaOutOXHi7idWFh+lcJ8+FDpTDtMeIm5s9+syJv3 ubNL11VRd6mMD4CRvRQQ3qLbP95Z6w1znuc0WSy+ca/MhxTaA0IhBLg95EKstG X-Google-Smtp-Source: AGHT+IFzaKuYyQXPqrElude6fdNNjcVkdXF8x+fIfOEW2Mf4YQ0UZ77zMOMl9/F7moGav80PJXDKxgegVP+NY/SVp4Q= X-Received: by 2002:a05:6214:f27:b0:6e8:fb92:dffa with SMTP id 6a1803df08f44-6e900632b1cmr200653976d6.25.1741643082832; Mon, 10 Mar 2025 14:44:42 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 10 Mar 2025 22:44:32 +0100 X-Gm-Features: AQ5f1Jo8yLCjmHYgWiV1F1HHK66LQ-SL0ARxyPRKryRwXM3pTd7DeMG_k9LWErw Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Never parameters To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Daniel On Mon, Mar 10, 2025 at 8:06=E2=80=AFPM Daniel Scherzer wrote: > > I'd like to start discussion on a new RFC about allowing `never` for para= meter types when declaring a method. > > * RFC: https://wiki.php.net/rfc/never-parameters-v2 > * Implementation: https://github.com/php/php-src/pull/18016 Thank you for your proposal! I would have slightly preferred to investigate associated types first. They mostly solve the same problem, except they can express relationships between other parameters or return types. For example: interface Enum { public type BackingType; // Potentially with `: int|float`? public function from(BackingType $value): static; public function tryFrom(BackingType $value): ?static; } This has a slightly more accurate signature, namely enforcing that from() and tryFrom() take the same argument type. Furthermore, you can use the same associated type in return types, whereas mixed would have to be used without them. I'd also argue it's easier to understand without deep knowledge of type systems. Associated types are similar to what a generic interface would give you, except: 1. Every class implementing this interface can only implement it once, restricting the associated type to one concrete type. This makes sense for PHP, given that we don't have method overloading, which would be required to make use of multiple generic interface implementations. 2. It's much simpler to implement than generics, given that this can be fully enforced during inheritance rather than runtime. I understand that associated types are still significantly more work than a never type, so I don't mind going with this solution. Given that BackedEnum cannot be implemented by users, migrating it to use associated types could be done without BC breaks. Ilija