Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126935 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 F00D91A00BC for ; Tue, 25 Mar 2025 18:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1742926351; bh=U3aysu63bpVKYwt9PwDNvVIePo7ZY5ke+G04bkSjh5Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=O8LEc7XgucKnceuKy/XDeCnZsUemTJZmeCpnsHMvmVStYle1kOny4cE+Q8SE3bLq0 AdztQlFN/6E4q7N8ZR2d1Ags0yJtnWWDkf03fspwce4dEDKfQeCRRhcobvPzfcCVdK kDLmhqyhs4DeCe+Qj9vnKqBw0ES4t92f8wwl21ZTzNUoQ5lvoeoVP+9yIP4M5RqTel /hI4rb2+9FFhvMyL+e8uhOetqR1Y6hHG4ZfLt8iZ6GgQgHncL2FV0wFg5zQuz3B5Hl jAhgbmDow9YK+3TIAv8HkG6NWBO0O7GcyHEOGKVIbaYqmcAVjOQfIqlODXdpazr/q/ i1HS1LDuLo2zA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7D573180079 for ; Tue, 25 Mar 2025 18:12:30 +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.5 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,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-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) (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 ; Tue, 25 Mar 2025 18:12:30 +0000 (UTC) Received: by mail-ua1-f54.google.com with SMTP id a1e0cc1a2514c-86b9b1def28so5547856241.3 for ; Tue, 25 Mar 2025 11:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742926499; x=1743531299; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VWr2lFNG7lcnydVSwTkP0XMNb3fQpIDB+JJKMC1zjM0=; b=d3PG64KBsYxbgWMTjIG3sh2stO+wYvzSa/uMN//x04ixE5TonfAqKXQxQDjpDmAKNa Pbm3XRKT1Xtdb5CSA9lHMvWcjXiTXVRPjBwikfWLFOvaXYYapOAgCE2X/NT+dbWXmVjG 4meyeq1oSiS08pGHKsIrE1D3HcrgaPtKewe979zkvjRFVpFCXFbPUGsbVaCHKzJRaNj3 lbBPGQmDajPpfpdL0I+gNTYKXzAe6iRkMSeLFMPWlLYTR9en2AC6RckTaPU0CG33E41s zOXt2f2QJNBFJ9KOMGbMhOgfyA4TZPaifrYTF2mHt9Dp5fULLJGdEws5fYBoBGG6RIuu oSLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742926499; x=1743531299; h=cc: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=VWr2lFNG7lcnydVSwTkP0XMNb3fQpIDB+JJKMC1zjM0=; b=dHrBO1kKWjg55U1RiiakPmtO264Xw/KAQzgDgbdixx5j80xQi1/PhxxJYB2DkIIKPQ s7OerLABUt0onMLU/4RkyyHjZDuYFDYk7ccDWb6tnNxmKtlTgvibGd4Of2085okxEi1H /cmBtNH/W0RFoU+Wbi0DHDTg7qI24QKFc5vUF9j2wqYU4b+EozKy+ETdE2xjsKccgGkY SHxZWaicSgNvdJx4VVRbJUQXlvG17uQrI08pfTY1Yd942+2/GU0ptqdm5YY2btOiCFSe NbpcQbZPI/ao1gO9/gOyXRr6pzFRQtIA/tq4jdm1obvEh1MSAJibgIJdT8d6pc4Fpqy7 80tw== X-Gm-Message-State: AOJu0YxII9QqvHBKs/UNkprNdmC80ZbhibJYHIpZnvDvcsYFUP979YtM oGPOOozMfT2GdCo3A3PE9WwZ4WntpsgnmL5TB5pyx0/nWlIf4wltD+0UN8mAi2pTx4Zj13krvm7 o1bRK2wqMMGH86JIXwpLOLGmDGow= X-Gm-Gg: ASbGncvx4Ah+bGlLf1AEAmR8FfVYtkC+wIKizdWcL4Lze8vGb0Jwyh2EaeFjeDJr3vJ tF278d8BiloTeRnsowcxNMZL8IP1cEtg0SAycUf57tIaGeH2VW09jGzMzO0NwiEGbqhUCIVkzdn eTnFQB3YTc4NRHL6NEQCc4pp+UtPG7JTWitirvxYuyVnoI1VKQv7jDyr0u0eiyL0S7RqbJ X-Google-Smtp-Source: AGHT+IHfbi662freTXWC0yD1LOZ4IkHZDWZBwBYQrUP7sFgQScf8o2W+W/+yTxtsXEvVSJbM/we+10pR80iClfY1De0= X-Received: by 2002:a05:6102:26cc:b0:4c1:9b88:5c30 with SMTP id ada2fe7eead31-4c50d5e3490mr14248077137.19.1742926498287; Tue, 25 Mar 2025 11:14:58 -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: Tue, 25 Mar 2025 11:14:21 -0700 X-Gm-Features: AQ5f1Jqpx-2xOYmzdgS7yAX7waSuHL-NTNS1FMZ72l3H3oeFh28rUCf0-xmld-k Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Never parameters To: "Rowan Tommins [IMSoP]" Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000ccd72d06312eb2d7" From: daniel.e.scherzer@gmail.com (Daniel Scherzer) --000000000000ccd72d06312eb2d7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 25, 2025 at 11:01=E2=80=AFAM Rowan Tommins [IMSoP] wrote: > > I don't think the language should pretend to support something that it > doesn't > I don't see what the pretending is here - the engine supports declaring that a method must accept a parameter but makes no promises about the type of that parameter, which is what we claim it supports. If people want to use this for generics, then great, but I don't think this should be blocked on the expectation that it is only useful for userland generics (e.g. the Serde use case isn't really generics). > - if the contract is actually enforced by a third-party tool reading > docblocks, put the contract in a docblock: > > /** > * @template T > * @method compareTo(T $other): int; > */ > interface Comparable { > } > > /** @implements Comparable */ > final class Number implements Comparable { > public function compareTo(Number $other): int { return $this <=3D= > > $other; } > } > > > What happens if there is a bigger contract than just the never parameter, and we want the engine to enforce the rest? For example, the Serde use case given previously. Or, if you had an object store that might occasionally clean up expired items: /** @template T */ interface ObjectStore { /** @param T $object */ public function storeObject(never $object, bool $alsoDoCleanup): void; } If we move the entire contract to the docblock, then the engine cannot be used to enforce the non-never-related parts. --Daniel --000000000000ccd72d06312eb2d7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Mar 25, 2025 at 11:01=E2=80=AFAM = Rowan Tommins [IMSoP] <imsop.php= @rwec.co.uk> wrote:
=20 =20 =20

I don't think the language should pretend to support something that it doesn't


I don't see= what the pretending is here - the engine supports declaring that a method = must accept a parameter but makes no promises about the type of that parame= ter, which is what we claim it supports. If people want to use this for gen= erics, then great, but I don't think this should=C2=A0be blocked on the= expectation that it is only useful for userland generics (e.g. the=C2=A0Se= rde use case isn't really generics).
=C2=A0

- if the contract is actuall= y enforced by a third-party tool reading docblocks, put the contract in a docblock:

=C2=A0=C2=A0=C2=A0 /**
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * @template T
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * @method compareTo(T $other): i= nt;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 */
=C2=A0=C2=A0=C2=A0 interface Comparable {
=C2=A0=C2=A0=C2=A0 }

=C2=A0=C2=A0=C2=A0 /** @implements Comparable<Number> */
=C2=A0=C2=A0=C2=A0 final class Number implements Comparable {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 public function compareTo(= Number $other): int { return $this <=3D> $other; }
=C2=A0=C2=A0=C2=A0 }


What happens if there is a bigger co= ntract than just the never parameter, and we want the engine to enforce the= rest? For example, the Serde use case given previously. Or, if you had an = object store that might occasionally clean up expired items:

= =C2=A0 =C2=A0 =C2=A0/** @template T */
=C2=A0 =C2=A0 =C2=A0interface Obj= ectStore {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0/** @param T $object */
= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0public function storeObject(never $object= , bool $alsoDoCleanup): void;
=C2=A0 =C2=A0 =C2=A0}

=
If we move the entire contract to the docblock, then the engine cannot= be used to enforce the non-never-related parts.

-= -Daniel
=C2=A0
--000000000000ccd72d06312eb2d7--