[php-src] Issue #20745: "Casting out of range floats to int" applies to strings
[email protected] (bwoebi)
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <3wY6LmhKNYD8VgtrtyBLHrlns9JTltheoKU4jNVFF18@main.internal.php.net> |
Issue: https://github.com/php/php-src/issues/20745 Author: bwoebi ### Description The following code: ```php <?php var_dump((int) "9999999999999999999"); ``` Resulted in this output: ``` PHP Warning: The float-string "9999999999999999999" is not representable as an int, cast occurred in Command line code on line 1 int(9223372036854775807) ``` But I expected this output instead: ``` int(9223372036854775807) ``` I just updated to PHP 8.5.0 and surprisingly started seeing these warnings. This was added with https://wiki.php.net/rfc/warnings-php-8-5#casting_out_of_range_floats_to_int, which explicitly talked about warning on non-representable floats. Not about strings. (I see the UPGADING entry got the `or strings that look like floats` added. But the RFC, what was voted on, does not.) Now, e.g. `(int) "a"` is fine emitting `0` as expected ... but once that string is something looking like a number, it suddenly emits a warning. This is especially problematic when accepting arbitrary user input like `(int) ($_POST['value'] ?? 0)`. I strongly object to this behaviour on strings - on floats, it's fine (and was voted on). ### PHP Version ```plain PHP 8.5.0 ``` ### Operating System _No response_