Re: [RFC] Add true as type

From: Date: Mon, 11 Apr 2022 13:45:15 +0000
Subject: Re: [RFC] Add true as type
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-117512@lists.php.net to get a copy of this message
Hi, On Mon, Apr 11, 2022 at 3:33 PM G. P. B. <george.banyard@gmail.com> 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 > 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. > > Not adding true as a type prevents extending methods which return bool to > always return true to clearly document this within the typesystem. > Then you should probably update the RFC to say that, and better examples ;) Maybe also add an example of "refinement" during inheritance (from : bool to : true)? One more thing: maybe the part about true|false being an error (use bool) should be its own subsection, as that's not exactly "redundancy", and differs from array|\Traversable being interchangeable with iterable. Regards, -- Guilliam Xavier

« previous php.internals (#117512) next »