[wp-trac] [WordPress Trac] #39053: Add function `wp_validate_integer`

WordPress Trac noreply at wordpress.org
Mon Feb 27 23:52:38 UTC 2017


#39053: Add function `wp_validate_integer`
----------------------------------------------------+------------------
 Reporter:  peterwilsoncc                           |       Owner:
     Type:  enhancement                             |      Status:  new
 Priority:  normal                                  |   Milestone:  4.8
Component:  General                                 |     Version:
 Severity:  normal                                  |  Resolution:
 Keywords:  has-patch has-unit-tests needs-refresh  |     Focuses:
----------------------------------------------------+------------------

Comment (by dd32):

 Replying to [comment:4 peterwilsoncc]:
 > @dd32 you mentioned in passing elsewhere this may fail with 64 bit
 numbers on 32 bit systems. Do you have any suggestions on how to fix this.
 >
 > `if ( ! is_numeric( $var ) || floor( $var ) != $var )` is used currently
 used in core, so it will need to be removed if that's the problematic
 line.

 I'm honestly not sure if it's an issue at all.
 Even on 64bit PHP `9223372036854775808` is 1 larger than what will fit
 inside an `int`, PHP automatically converts it to a `float` in that case,
 and the above code will pass as expected.
 However, if you attempt to cast it to an int `(int)9223372036854775808`
 you'll get `-9223372036854775808` as the value you're operating upon,
 which is highly unexpected - so don't cast things to `(int)`..

 ref: http://php.net/manual/en/language.types.integer.php

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


More information about the wp-trac mailing list