[wp-trac] [WordPress Trac] #65271: REST API Integer Type Check Fails on Large Ints
WordPress Trac
noreply at wordpress.org
Wed May 20 16:08:47 UTC 2026
#65271: REST API Integer Type Check Fails on Large Ints
--------------------------------------+-----------------------------
Reporter: kevinfodness | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future Release
Component: REST API | Version: 5.5
Severity: minor | Resolution:
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+-----------------------------
Comment (by mboynes):
@siliconforks it's true that `round()` impacts the issue starting in PHP
8.4, but only in that it moves the starting point from 2^53^ to 2^52^; the
heart of the issue remains.
Example:
{{{
php > var_dump(floor((float) '9007199254740992'));
float(9007199254740992)
php > var_dump(floor((float) '9007199254740993'));
float(9007199254740992)
php > var_dump(floor((float) '9007199254740994'));
float(9007199254740994)
}}}
The real problem is that 2^53^ is the line after which double-precision
floats can no longer represent every integer exactly, as @gautam23
mentioned above. Better illustrated without the use of `round()` or
`floor()`:
{{{
php > var_dump((float) 9007199254740993);
float(9007199254740992)
}}}
I agree with the idea to use regex here, or we could also cast to an int
then back to a string and compare against the original string...
{{{
php > $maybe_integer = '9223372036854775807';
php > var_dump((string)(int) $maybe_integer === (string) $maybe_integer);
bool(true)
}}}
There is still a problem lurking around here, such that the database can
store larger integers than PHP can handle.
{{{
php > $maybe_integer = '9223372036854775808'; // PHP_INT_MAX + 1
php > var_dump((string)(int) $maybe_integer === (string) $num);
bool(false)
php > echo PHP_INT_MAX + 1;
9.2233720368548E+18
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/65271#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list