Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ PHP NEWS
. Fixed bug GH-13354 (pg_execute/pg_send_query_params/pg_send_execute
with null value passed by reference). (George Barbarosie)

- Random:
. Fixed bug GH-13544 (Pre-PHP 8.2 compatibility for mt_srand with
unknown modes). (timwolla)

- Standard:
. Fixed array key as hash to string (case insensitive) comparison typo
for the second operand buffer size (albeit unused for now). (A. Slepykh)
Expand Down
8 changes: 7 additions & 1 deletion ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,13 @@ PHP_FUNCTION(mt_srand)
Z_PARAM_LONG(mode)
ZEND_PARSE_PARAMETERS_END();

state->mode = mode;
switch (mode) {
case MT_RAND_PHP:
state->mode = MT_RAND_PHP;
break;
default:
state->mode = MT_RAND_MT19937;
}

if (ZEND_NUM_ARGS() == 0) {
php_random_mt19937_seed_default(status->state);
Expand Down
22 changes: 22 additions & 0 deletions ext/random/tests/01_functions/mt_srand_unknown_mode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
mt_srand(): Test unknown modes
--FILE--
<?php
// MT_RAND_MT19937
mt_srand(1, 0);
var_dump(mt_rand());
// MT_RAND_PHP
mt_srand(1, 1);
var_dump(mt_rand());
// Unknown
mt_srand(1, 2);
var_dump(mt_rand());
// Equivalent to 0 when cast as unsigned 8-bit integer
mt_srand(1, 256);
var_dump(mt_rand());
?>
--EXPECT--
int(895547922)
int(1244335972)
int(895547922)
int(895547922)