Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115716 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 84581 invoked from network); 14 Aug 2021 12:33:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Aug 2021 12:33:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9818D1804B3 for ; Sat, 14 Aug 2021 06:05:17 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 ; Sat, 14 Aug 2021 06:05:17 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id AE32A3200914 for ; Sat, 14 Aug 2021 09:05:15 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Sat, 14 Aug 2021 09:05:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=7CWVVD icKbVmFBlnx4MURhtaZwnFeyjbEXUrB5WbpC4=; b=s0Guwvz8Do38oCPWaUNIn5 Qky5AGLHf68qtLZfMJv6uraqV+Jd3ttxWYMAFZJ4JojK0fAQTyiRGphXLVXn/NwM 2k0dACBXRiO40meK1FBfgT87dqFXJgiwNXObqDf6LZVLUdid18dD41Q7H1/R2uzj GFCkuvIAsyb+gktTgC0s3oOSeEj6JGP+AH3e42hfhf40n18qI5Angwc1Zh9aGxHZ gDPTYVGLRQ00Dl9ExxBJ9GgEyt8wry2r+9NIGugO3JS+azNviBHJINXOfOS7RJgP q+6pMiieT3ND7oBrHVcDOwoCtQQuSPH8/rDFGDnIfTD518PXg4rmAUrnV0bsQzdg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkeejgdeiudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenog fuuhhsphgvtghtffhomhgrihhnucdlgeelmdenucfjughrpefofgggkfgjfhffhffvufgt sehttdertderredtnecuhfhrohhmpedfnfgrrhhrhicuifgrrhhfihgvlhgufdcuoehlrg hrrhihsehgrghrfhhivghlughtvggthhdrtghomheqnecuggftrfgrthhtvghrnhepjeei gfejlefhjeeuhfelgeevkedvvedvuddvheevfeehfeffveetvdffuddvfffhnecuffhomh grihhnpeefvheglhdrohhrghdpghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguth gvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id D2CD1AC0E77; Sat, 14 Aug 2021 09:05:14 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-1082-gccb13bca62-fm-ubox-20210811.001-gccb13bca Mime-Version: 1.0 Message-ID: <756e4d26-2e57-4d31-83ea-28e756c3cc42@www.fastmail.com> In-Reply-To: References: Date: Sat, 14 Aug 2021 08:04:33 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Never For Argument Types From: larry@garfieldtech.com ("Larry Garfield") On Sat, Aug 14, 2021, at 7:48 AM, G. P. B. wrote: > On Sat, 14 Aug 2021 at 10:55, Deleu wrote: > > > Hi Jordan, > > > > Does it make sense to explain in the RFC the difference between never and > > mixed in this context? The RFC vaguely mentions that never can never be > > used directly, but if it's limited to abstract class and interfaces, isn't > > that already impossible to use directly? Or does it mean that the type > > would "be allowed" on any function, but because of its intrinsic behavior > > it would always fail if used in non-abstract methods? > > > > Another clarification I'd be interested is about dropping the type > > declaration entirely (e.g. https://3v4l.org/a4bfs), because of covariance > > (or contravariance, I never know), sub classes can completely drop type > > declaration entirely. Will never not allow this? Why? Why not? If it does > > allow this, does it really differ from not having any type declaration on > > the abstract function? > > > > My knowledge in this area is practically null so if I'm asking stupid > > questions that are easily explained by some blog post I'd he happy to read > > it. > > > > never and mixed are on opposite sides of the type hierarchy. > mixed is the top type, meaning it's the supertype of any other types, and > any other type is a subtype of mixed (excluding void which is not really a > "type" if you look at it, from my understanding, in a type theory way). > never on the other side is the bottom type, meaning it's the subtype of any > other type, and any other type is a supertype of never. > Finally a lack of type declaration is treated as mixed. > > Liskov's substitutions rules dictate that return types are co-variant i.e. > more specific, and argument types are contra-variant i.e. more general. > This is why any return type can be replaced by never and any argument type > can have it's type dropped/changed to mixed. > As such replacing never by mixed in an argument is totally possible as > mixed is a wider type than never. > > How I personally see never as an argument type is that you require a > mandatory argument but you leave the type constraint up to the > implementation. > > A recent example which bit us in php-src/the PHP documentation is the > interface of ArrayAccess, all of the $offset parameters have a mixed type. > Until recently the ArrayObject/ArrayIterator had incorrect stubs [1] by > indicating that the argument was of type int|string, which practically is > the case as SPL's ArrayAccess handler will throw a TypeError on different > types, however this is done manually within the call and not when the call > is made. > Ideally the $offset parameter would be of type never such that SPL, and > userland, can specify what type of offsets they accept, be that the usual > int|string, only int for list-like objects, only string for dictionary-like > objects, maybe even object|int|string to allow GMP objects for arbitrary > precision. > Whereas every implementer of ArrayAccess is forced to accept mixed for the > $offset and need to manually enforce the type. > > This is the "power" of the never type as an argument type. > > Best regards, > > George P. Banyard > > [1] > https://github.com/php/php-src/pull/7215/files#diff-e330df347cac9e68d2d07a06535c534cd8c2438a1af703cd4245b8ce91ec65afL9-R10 So... if I am following correctly, the idea is to allow `never` to be used in an interface/abstract method only, as a way to indicate "you must specify a type here of some kind; I don't care what, even mixed, but you have to put something". Am I following? I'm not sure on the type theory of it, but it does feel like a hack at first blush. --Larry Garfield