forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pre-PHP 8.2 compatibility for php_mt_rand_range() with MT_RAND_PHP
As some left-over comments indicated: > Legacy mode deliberately not inside php_mt_rand_range() > to prevent other functions being affected The broken scaler was only used for `php_mt_rand_common()`, not `php_mt_rand_range()`. The former is only used for `mt_rand()`, whereas the latter is used for `array_rand()` and others. With the refactoring for the introduction of ext/random `php_mt_rand_common()` and `php_mt_rand_range()` were accidentally unified, thus introducing a behavioral change that was reported in FakerPHP/Faker#528. This commit moves the checks for `MT_RAND_PHP` from the general-purpose `range()` function back into `php_mt_rand_common()` and also into `Randomizer::getInt()` for drop-in compatibility with `mt_rand()`.
- Loading branch information
Showing
4 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
array_rand() is not affected by MT_RAND_PHP as with PHP < 8.2 | ||
--FILE-- | ||
<?php | ||
|
||
$array = [ | ||
'foo', | ||
'bar', | ||
'baz', | ||
]; | ||
|
||
mt_srand(1, MT_RAND_PHP); | ||
function custom_array_rand() { | ||
global $array; | ||
$key = array_rand($array); | ||
var_dump('found key ' . $key); | ||
return $array[$key]; | ||
} | ||
|
||
var_dump( | ||
custom_array_rand(), | ||
custom_array_rand(), | ||
custom_array_rand(), | ||
); | ||
?> | ||
--EXPECTF-- | ||
string(11) "found key 0" | ||
string(11) "found key 1" | ||
string(11) "found key 0" | ||
string(3) "foo" | ||
string(3) "bar" | ||
string(3) "foo" |