WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/23/2015 04:21:01 AM (6 years ago)
Author:
dd32
Message:

Update to Random_Compat 1.0.9.
This update includes fixes for Windows support & libSodium support, and removes the Throwable Polyfill due to PHP7 incompatibilities.

Fixes #28633

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/random_compat/random_int.php

    r34922 r35365  
    4141    /**
    4242     * 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.
    4349     */
    44     if (!is_numeric($min)) {
     50   
     51    try {
     52        $min = RandomCompat_intval($min);
     53    } catch (TypeError $ex) {
    4554        throw new TypeError(
    4655            'random_int(): $min must be an integer'
    4756        );
    4857    }
    49     if (!is_numeric($max)) {
     58    try {
     59        $max = RandomCompat_intval($max);
     60    } catch (TypeError $ex) {
    5061        throw new TypeError(
    5162            'random_int(): $max must be an integer'
    5263        );
    5364    }
    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     */
    5871    if ($min > $max) {
    5972        throw new Error(
     
    165178         * If $val overflows to a floating point number,
    166179         * ... or is larger than $max,
    167          * ... or smaller than $int,
     180         * ... or smaller than $min,
    168181         * then try again.
    169182         */
Note: See TracChangeset for help on using the changeset viewer.