On Mon, 15 Jun 2026 at 19:43, Tim Düsterhus <[email protected]> wrote: > > Hi > > On 6/15/26 03:22, Seifeddine Gmati wrote: > > I'd like to start the discussion on a new RFC adding literal scalar > > types to PHP. > > > > - RFC: https://wiki.php.net/rfc/literal_scalar_types > > - Implementation: https://github.com/php/php-src/pull/22314 > > I have given the RFC a quick first review pass and would suggest to > leave out support for float literals. From a conceptual perspective > floats are much closer to being continuous values than they are to > discrete values and picking individual values from a continuous range is > typically not all that useful. > > Support for floats is also going to invite the usual confusion about > implicit rounding: > > function tenths( > 0.0|0.1|0.2|0.3|0.4|0.5|0.6|0.7|0.8|0.9 $tenth > ): void { var_dump($tenth); } > > where `tenths(0.1 + 0.2)` will result in a TypeError. The RFC is also > unclear what values are valid floating point literals. As an example, is > `4e3` a valid float literal? Is NAN a valid float literal? > > Best regards > Tim Düsterhus
Hi Tim, I think I might agree here, and others have raised the same concern on Discord. Dropping float literals for now simplifies the RFC, so I am inclined to do that, though I would like to hear what others think before removing them. For what it is worth, I am personally fine with `tenths(0.1 + 0.2)` failing to match `0.3`. This is not new behaviour: `0.1 + 0.2 == 0.3` is already false, and a `match (0.1 + 0.2)` already skips a `0.3` arm for exactly the same reason. So a literal float type behaves consistently with comparison and `match`, rather than introducing a new surprise. On your concrete questions: `4e3` is a valid float literal and works today; it normalizes to `4000.0` (the type also stringifies as `4000.0`). `NAN` and `INF`, on the other hand, are not literals but constant identifiers that go through constant resolution. They are out of scope for the same reason `FOO` is above: `NAN $foo` could just as well mean a class named `NAN`.
