Skip to content

Fix GH-10292 make the default value of the first param of srand() and mt_srand() nullable #10380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,19 +675,20 @@ PHP_FUNCTION(lcg_value)
PHP_FUNCTION(mt_srand)
{
zend_long seed = 0;
bool seed_is_null = 1;
zend_long mode = MT_RAND_MT19937;
php_random_status *status = RANDOM_G(mt19937);
php_random_status_state_mt19937 *state = status->state;

ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(seed)
Z_PARAM_LONG_OR_NULL(seed, seed_is_null)
Z_PARAM_LONG(mode)
ZEND_PARSE_PARAMETERS_END();

state->mode = mode;

if (ZEND_NUM_ARGS() == 0) {
if (seed_is_null) {
php_random_mt19937_seed_default(status->state);
} else {
php_random_algo_mt19937.seed(status, (uint64_t) seed);
Expand Down
4 changes: 2 additions & 2 deletions ext/random/random.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

function lcg_value(): float {}

function mt_srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {}
function mt_srand(?int $seed = null, int $mode = MT_RAND_MT19937): void {}

/** @alias mt_srand */
function srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {}
function srand(?int $seed = null, int $mode = MT_RAND_MT19937): void {}

function rand(int $min = UNKNOWN, int $max = UNKNOWN): int {}

Expand Down
4 changes: 2 additions & 2 deletions ext/random/random_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.