Re: [RFC] Add true as type

From: Date: Mon, 11 Apr 2022 13:59:45 +0000
Subject: Re: [RFC] Add true as type
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-117513@lists.php.net to get a copy of this message
Hi On 4/11/22 15:32, G. P. B. wrote:
There are many many many more internal functions in PHP which only return true, but only since PHP 8.0.0, and this is due to the huge amount of E_WARNING to ValueError/TypeError promotion which has happened. These functions previously did return false in certain circumstances, and
I see. I think you should clarify this in the "Examples" section, that (some of) these functions previously were an actual : bool instead of : true.
although I agree that changing these to void *would* be the most ideal, being able to do this communicating that these functions only return true (which means one can ignore the return value) is the first step. Moreover, it is even more of a BC break compared to changing something which only returns false to void as code like: if (always_true(...)){ ... } would stop executing this code path.
I was not attempting to argue that the return type should be changed to : void (because of the obvious BC issues). Instead I believe that probably would choose an entirely different return type if the functions would be newly introduced.
Not adding true as a type prevents extending methods which return bool to always return true to clearly document this within the typesystem.
This argument was also used for allowing null / false as a standalone type, because there is no good reason to allow null / false in a union type, but not standalone. For true the story is different, as this type is an entirely new type available to userland and by the same argument one could have literal strings or literal integers as distinct types as well. I wouldn't object to that per se (and there's precedent in TypeScript), but there could be a clearer plan for the type system as a whole, instead of adding types piecemeal. I *can* see the value in having true for completeness, though. Best regards Tim Düsterhus

« previous php.internals (#117513) next »