Revert [34922] pending PHP 5.2 compatibility.

See #28633


git-svn-id: https://develop.svn.wordpress.org/trunk@34924 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse
2015-10-08 00:16:07 +00:00
parent 6cc5757f10
commit ebbe91ad8d
10 changed files with 3 additions and 854 deletions

View File

@@ -2132,11 +2132,9 @@ if ( !function_exists('wp_rand') ) :
* Generates a random number
*
* @since 2.6.2
* @since 4.4 Uses PHP7 random_int() or the random_compat library if avaialble.
*
* @global string $rnd_value
* @staticvar string $seed
* @staticvar bool $external_rand_source_available
*
* @param int $min Lower limit for the generated number
* @param int $max Upper limit for the generated number
@@ -2145,34 +2143,6 @@ if ( !function_exists('wp_rand') ) :
function wp_rand( $min = 0, $max = 0 ) {
global $rnd_value;
// Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
$max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff
// We only handle Ints, floats are truncated to their integer value.
$min = (int) $min;
$max = (int) $max;
// Use PHP's CSPRNG, or a compatible method
static $use_random_int_functionality = true;
if ( $use_random_int_functionality ) {
try {
$_max = ( 0 != $max ) ? $max : $max_random_number;
// wp_rand() can accept arguements in either order, PHP cannot.
$_max = max( $min, $_max );
$_min = min( $min, $_max );
$val = random_int( $_min, $_max );
if ( false !== $val ) {
return absint( $val );
} else {
$use_random_int_functionality = false;
}
} catch ( Throwable $t ) {
$use_random_int_functionality = false;
} catch ( Exception $e ) {
$use_random_int_functionality = false;
}
}
// Reset $rnd_value after 14 uses
// 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
if ( strlen($rnd_value) < 8 ) {
@@ -2197,6 +2167,9 @@ function wp_rand( $min = 0, $max = 0 ) {
$value = abs(hexdec($value));
// Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.
$max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff
// Reduce the value to be within the min - max range
if ( $max != 0 )
$value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );