[wp-trac] [WordPress Trac] #65271: REST API Integer Type Check Fails on Large Ints

WordPress Trac noreply at wordpress.org
Wed May 20 17:41:02 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 siliconforks):

 Replying to [comment:16 mboynes]:
 > @siliconforks good question, and sorry I wasn't clear on that. Here's an
 example of why it matters, why `floor()` doesn't solve the root issue, and
 why this needs a different validation mechanism (probably something
 string-based):
 >
 > {{{
 > php > $maybe_integer = '9007199254740993.1';
 > php > var_dump(floor( (float) $maybe_integer ) === (float)
 $maybe_integer);
 > bool(true)
 > }}}
 >
 > In fact, this problem surfaces at 2^50^ if we're including decimals,
 since the double needs bits to represent the decimal...
 >
 > {{{
 > php > $maybe_integer = 2**49 + 0.1;
 > php > var_dump(floor( (float) $maybe_integer ) === (float)
 $maybe_integer);
 > bool(false)
 > php > $maybe_integer = 2**50 + 0.1;
 > php > var_dump(floor( (float) $maybe_integer ) === (float)
 $maybe_integer);
 > bool(true)
 > }}}

 That's kind of an edge case, since it isn't actually possible to represent
 numbers like `9007199254740993.1` or `2**50 + 0.1` as floats.  If you try
 to do it, what you get is actually an integer, so `rest_is_integer`
 returning `true` is arguably correct.  (In any case, I wouldn't recommend
 changing that behavior now - this function has been around for 6 years and
 there may be someone, somewhere relying on the current behavior.)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/65271#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list