mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
Fix GH-10292 make the default value of the first parame of srand() and mt_srand() nullable (#10380)
Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
This commit is contained in:
parent
db6840bda4
commit
1f05d6ef80
2
NEWS
2
NEWS
@ -76,6 +76,8 @@ PHP NEWS
|
||||
- Random:
|
||||
. Added Randomizer::getBytesFromString(). (Joshua Rüsweg)
|
||||
. Added Randomizer::nextFloat(), ::getFloat(), and IntervalBoundary. (timwolla)
|
||||
. Fix GH-10292 (Made the default value of the first param of srand() and
|
||||
mt_srand() nullable). (kocsismate)
|
||||
|
||||
- Reflection:
|
||||
. Fix GH-9470 (ReflectionMethod constructor should not find private parent
|
||||
|
@ -88,6 +88,10 @@ PHP 8.3 UPGRADE NOTES
|
||||
RFC: https://wiki.php.net/rfc/randomizer_additions
|
||||
. Added Randomizer::nextFloat(), ::getFloat(), and IntervalBoundary.
|
||||
RFC: https://wiki.php.net/rfc/randomizer_additions
|
||||
. Changed mt_srand() and srand() to not check the number of arguments to
|
||||
determine whether a random seed should be used. Passing null will generate
|
||||
a random seed, 0 will use zero as the seed. The functions are now consistent
|
||||
with Mt19937::__construct().
|
||||
|
||||
- Sockets:
|
||||
. Added socket_atmark to checks if the socket is OOB marked.
|
||||
|
@ -675,19 +675,20 @@ PHP_FUNCTION(lcg_value)
|
||||
PHP_FUNCTION(mt_srand)
|
||||
{
|
||||
zend_long seed = 0;
|
||||
bool seed_is_null = true;
|
||||
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);
|
||||
|
@ -16,10 +16,10 @@ namespace {
|
||||
|
||||
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 {}
|
||||
|
||||
|
4
ext/random/random_arginfo.h
generated
4
ext/random/random_arginfo.h
generated
@ -1,11 +1,11 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: 7b9594d2eadb778ecec34114b67f2d0ae8bbb58a */
|
||||
* Stub hash: 533dc78162cc1e510f7c87971a6350acd43de1ab */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_lcg_value, 0, 0, IS_DOUBLE, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mt_srand, 0, 0, IS_VOID, 0)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, seed, IS_LONG, 0, "0")
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, seed, IS_LONG, 1, "null")
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "MT_RAND_MT19937")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user