Changeset 35365 for trunk/src/wp-includes/random_compat/random_int.php
- Timestamp:
- 10/23/2015 04:21:01 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/random_compat/random_int.php
r34922 r35365 41 41 /** 42 42 * Type and input logic checks 43 * 44 * If you pass it a float in the range (~PHP_INT_MAX, PHP_INT_MAX) 45 * (non-inclusive), it will sanely cast it to an int. If you it's equal to 46 * ~PHP_INT_MAX or PHP_INT_MAX, we let it fail as not an integer. Floats 47 * lose precision, so the <= and => operators might accidentally let a float 48 * through. 43 49 */ 44 if (!is_numeric($min)) { 50 51 try { 52 $min = RandomCompat_intval($min); 53 } catch (TypeError $ex) { 45 54 throw new TypeError( 46 55 'random_int(): $min must be an integer' 47 56 ); 48 57 } 49 if (!is_numeric($max)) { 58 try { 59 $max = RandomCompat_intval($max); 60 } catch (TypeError $ex) { 50 61 throw new TypeError( 51 62 'random_int(): $max must be an integer' 52 63 ); 53 64 } 54 55 $min = (int) $min; 56 $max = (int) $max; 57 65 66 /** 67 * Now that we've verified our weak typing system has given us an integer, 68 * let's validate the logic then we can move forward with generating random 69 * integers along a given range. 70 */ 58 71 if ($min > $max) { 59 72 throw new Error( … … 165 178 * If $val overflows to a floating point number, 166 179 * ... or is larger than $max, 167 * ... or smaller than $ int,180 * ... or smaller than $min, 168 181 * then try again. 169 182 */
Note: See TracChangeset
for help on using the changeset viewer.