Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127542 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 lists.php.net (Postfix) with ESMTPS id BDA451A00BC for ; Mon, 2 Jun 2025 20:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1748897321; bh=fIVyQBI07QbYExYuOsOARAw78KC4Dh7yujEAKYFzSOA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Z42t0lZjTZoEcR+eaGsBq1ixQTvA4RQMGHdxj/HzU86EtjybuwsiSEAmXXarYuMYf nFo/pJFjuX2oy3aVx9OovVZPKUZI+KB8gl7yFa6i5O7N3NgVoUTcmAO/vmGm/6XhWd Q9aKCImm1KU96lt/Clw9wPp9Xe13Oc+oa1099EeN0i/C5piFlnpRQN/fORH0XFbeEZ lP5HBxjOeL4TOC6gb9YsNQdj+Ft6d8YoOpJgbJClTp8YPVldsf92Com33Yd1ysKOBv eJxe1OOPJu1o8R5gY8i0/QFGQEumXJnXj1lKJe+3gwtxz52U0GB8OATSXO51HCbLgf swkdqPxXc07jQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4E008180081 for ; Mon, 2 Jun 2025 20:48:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 2 Jun 2025 20:48:40 +0000 (UTC) Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 26B021140186 for ; Mon, 2 Jun 2025 16:50:44 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Mon, 02 Jun 2025 16:50:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1748897444; x=1748983844; bh=j3ggtWXXE8 +ScYbvXKiTX6St8UHJflu3tzevV3bTW6o=; b=T3WejquTIcG2jiR0kz6rtvJ9LC uMwjXiJY2QhBc36G7ak75oAP4qBt5K3HGy2hOZDPtrL6mAjF5QbxlQR1dTNGaG53 ++5x8HUWCobamDKEf7m6ODvGm108U2r/VQMF8ocNLr/TeBGhvyuDoK9FFdgBp52C r7zqaKXEiIMTTv0zjPghXuEMHU2wZUxtPDRy/F1j4VwaJtQ01M5qWgRp5I4u3JDT eVg4jpOrq6ux5YqvyxZ1c176hfIRzOLejPmw/jay1R+u7vFzd0meNzedeiDDMbQ7 gOyDQWVIHYR2kGFqbr8vhmOuXjvS208OXHXaSi2Z32rmy2gTEPgxnVrhRTLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1748897444; x=1748983844; bh=j3ggtWXXE8+ScYbvXKiTX6St8UHJflu3tze vV3bTW6o=; b=cCyKFPxGtjbM9Aip7g40l4m+jAMXpUGh5whaUqVh8gr1sRZ1aYg tvUPTriwbqSpYodb9eWLw+ddxyyYpBz23zghMnGJgCR5thxaDpmAy7GyYmbDNAww 7ACTwJwS/B4+hlj/3Sk6RK1+dXWHbwOmkvgpvJFHpXXywRIjRoYMwlgIjylxQ4AG Yfx4fK3ItzrVvmfrzI+5A8VVABwxwWX3682JZPvlxNQAaKolHpBXMxznUb1fXXUF uatxRyXmVl1N6E1HI3QSleqj+DB/agsK12yKCG1fNo+F4nU0t9C03Y3WHz+pHj1F pcQUQsQdCI1Oef5e605AKvSE18qOrYjnMiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgdefkeeijeculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpedf tfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdfuceoihhmshhophdrphhhphesrh ifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpeehteelieeigfeuudeiueeiffdv veehudeufeekjeeugffffedtiedtgeettdelteenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprdhphhhpsehrfigvtgdrtghordhu khdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepih hnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 2 Jun 2025 16:50:43 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------5gTV5N99HR0T5UBciazQVLjR" Message-ID: <7f7dc3dc-bb9a-4f6e-9b77-055c4a8801d1@rwec.co.uk> Date: Mon, 2 Jun 2025 21:50:42 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Transform void into an alias for null Content-Language: en-GB To: internals@lists.php.net References: <6Z2Ysh6MjYp1nyzuB0bTPJc5srObIcMRqt731JaQeXUJk1f_V_Yo2nRn8WvjI7er7pp7pIUE6WYl5pRwvYrtcrd07nCutyAqKPSsZHmrS-Y=@gpb.moe> In-Reply-To: <6Z2Ysh6MjYp1nyzuB0bTPJc5srObIcMRqt731JaQeXUJk1f_V_Yo2nRn8WvjI7er7pp7pIUE6WYl5pRwvYrtcrd07nCutyAqKPSsZHmrS-Y=@gpb.moe> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------5gTV5N99HR0T5UBciazQVLjR Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 02/06/2025 17:27, Gina P. Banyard wrote: > The objective is to fix a weird quirk of PHP's type system, where void lives in its own type hierarchy. > This is visible mainly in that a lack of return type is not isomorphic to a function that has a return type of mixed. I think if "void" was added now, it would be an attribute, rather than a type. It is in effect the exact opposite of #[\NoDiscard], and distinguishes between these two cases: interface Foo {    public function getSomething(): ?Something; } class MyFoo implements Foo {    public function getSomething(): null {        // My result is always null, but still meaningful to consumers of the Foo interface        return null;    }    #[\DiscardReturn]    public function doSomething(): null {         // I have no meaningful information to return; any assignment of my implicit value is a mistake    } } I agree the type hierarchy you describe is weird, but rather than throwing away the functionality completely, I wonder if we can make it more consistent: - Make "no return type declared" and "mixed" equivalent - Make "void" a sub-type of "null", and therefore a sub-type of "mixed" If I've got that right, this would then be legal: class A{ public function foo() {} } class B extends A{ public function foo(): mixed{} } class C extends B{ public function foo(): null{} } class D extends C{ public function foo(): void{} } class E extends D{ public function foo(): never {} } That seems reasonable enough; I may have missed something important, though. Regards, -- Rowan Tommins [IMSoP] --------------5gTV5N99HR0T5UBciazQVLjR Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 02/06/2025 17:27, Gina P. Banyard wrote:
The objective is to fix a weird quirk of PHP's type system, where void lives in its own type hierarchy.
This is visible mainly in that a lack of return type is not isomorphic to a function that has a return type of mixed.


I think if "void" was added now, it would be an attribute, rather than a type. It is in effect the exact opposite of #[\NoDiscard], and distinguishes between these two cases:

interface Foo {
   public function getSomething(): ?Something;
}

class MyFoo implements Foo {
   public function getSomething(): null {
       // My result is always null, but still meaningful to consumers of the Foo interface
       return null;
   }

   #[\DiscardReturn]
   public function doSomething(): null {
        // I have no meaningful information to return; any assignment of my implicit value is a mistake
   }
}

I agree the type hierarchy you describe is weird, but rather than throwing away the functionality completely, I wonder if we can make it more consistent:

- Make "no return type declared" and "mixed" equivalent
- Make "void" a sub-type of "null", and therefore a sub-type of "mixed"

If I've got that right, this would then be legal:

class A { public function foo() {} }
class B extends A { public function foo(): mixed {} }
class C extends B { public function foo(): null {} }
class D extends C { public function foo(): void {} }
class E extends D { public function foo(): never {} }

That seems reasonable enough; I may have missed something important, though.

Regards,

-- 
Rowan Tommins
[IMSoP]
--------------5gTV5N99HR0T5UBciazQVLjR--