Skip to content

Commit 8bf70af

Browse files
committed
random: Fix unknown mt_srand() compatibility for unknown modes
PHP 8.1 and below interpreted unknown modes as `MT_RAND_MT19937`, but PHP 8.2+ interprets them as `MT_RAND_PHP`. Align the behavior with PHP 8.1 and below, because folks should be steered towards the standard mode.
1 parent f732ab8 commit 8bf70af

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ PHP NEWS
2828
. Fixed bug GH-13354 (pg_execute/pg_send_query_params/pg_send_execute
2929
with null value passed by reference). (George Barbarosie)
3030

31+
- Random:
32+
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with
33+
unknown modes). (timwolla)
34+
3135
- Standard:
3236
. Fixed array key as hash to string (case insensitive) comparison typo
3337
for the second operand buffer size (albeit unused for now). (A. Slepykh)

ext/random/random.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,13 @@ PHP_FUNCTION(mt_srand)
688688
Z_PARAM_LONG(mode)
689689
ZEND_PARSE_PARAMETERS_END();
690690

691-
state->mode = mode;
691+
switch (mode) {
692+
case MT_RAND_PHP:
693+
state->mode = MT_RAND_PHP;
694+
break;
695+
default:
696+
state->mode = MT_RAND_MT19937;
697+
}
692698

693699
if (ZEND_NUM_ARGS() == 0) {
694700
php_random_mt19937_seed_default(status->state);

0 commit comments

Comments
 (0)