News for hackers. Stuff that matters.
Re:Whats New in PHP 8.2 by steve_adams_86 on Monday April 25, 2022 @10:56AM (#31155760)
This works fine in TypeScript. You can specify a type as boolean, true, or false, and it works exactly as you’d expect. I don’t see an issue with doing the same in PHP
Re:Whats New in PHP 8.2 by bow_ on Monday April 25, 2022 @01:13PM (#31157842)
Introducing `false` as a standalone type but not `true` is what makes this weird. Generic, literal returns are fine. Python is another language that has it [1].

The introduction of the RFC [2] also still mentions `false` is of type bool:

> null corresponds to PHP's unit type, i.e. the type which holds a single value. false is a literal type of type bool.

But why call it bool if `true` is not a standalone type too?

[1] https://docs.python.org/3/library/typing.html#typing.Literal

[2] https://wiki.php.net/rfc/null-false-standalone-types

Re:Whats New in PHP 8.2 by cestith on Monday April 25, 2022 @11:01AM (#31155828)
It would not surprise me any to have a Boolean type and have both true and false as restricted subtypes of that. However, in this case of it being used primarily as a return type for failure in a function call, I think they're conflating the tradition from C-style languages of returning a false-ish value in-bound rather than creating a type specific to the error condition.
Re:Whats New in PHP 8.2 by masklinn on Monday April 25, 2022 @03:58PM (#31159753)
> I think they're conflating the tradition from C-style languages of returning a false-ish value in-bound

It’s not really conflation when php has been doing that since forever as it originally was little more than a thin shim over C (you can see that in lots of older APIs e.g. the mysql_ stuff is straight transcribed from the C library).