Too big `string` to `int` cast results nonsense
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
if ( (string) PHP_INT_MAX === '9223372036854775808' ) {
echo "string identical" . PHP_EOL;
}
if ( PHP_INT_MAX === (int) '9223372036854775808' ) {
echo "int identical" . PHP_EOL;
}
Resulted in this output:
int identical
But I expected this output instead:
Deprecated: Conversion from string '9223372036854775808' to int loses precision
A very similar error already exists when converting float to int implicitly e.g. $a[ PHP_INT_MAX + 1 ] = '';
See also https://github.com/php/php-src/issues/17081 which reports that for float/int casts
PHP Version
PHP 8.4.8
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the string-to-int cast behavior on PHP 8.4.8, then trace the PHP interpreter's string-to-integer conversion path. Compare it with the existing float-to-int precision-loss handling referenced in the issue. Done means the oversized string conversion reports the expected deprecation instead of silently producing PHP_INT_MAX.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100