Skip to content

Commit 3197104

Browse files
committed
Fix GH-10292 1st param of mt_srand() has UNKNOWN default on PHP <8.3
Closes GH-10429
1 parent 2787e3c commit 3197104

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Core:
66
. Fixed incorrect check condition in ZEND_YIELD. (nielsdos)
77

8+
- Standard:
9+
. Fixed bug GH-10292 (Made the default value of the first param of srand() and
10+
mt_srand() unknown). (kocsismate)
11+
812
02 Feb 2023, PHP 8.1.15
913

1014
- Apache:

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,10 +1548,10 @@ function quoted_printable_encode(string $string): string {}
15481548

15491549
/* mt_rand.c */
15501550

1551-
function mt_srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {}
1551+
function mt_srand(int $seed = UNKNOWN, int $mode = MT_RAND_MT19937): void {}
15521552

15531553
/** @alias mt_srand */
1554-
function srand(int $seed = 0, int $mode = MT_RAND_MT19937): void {}
1554+
function srand(int $seed = UNKNOWN, int $mode = MT_RAND_MT19937): void {}
15551555

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

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 87ed2b04b9b46ce3df78d6f9d6d62bd6b2ae8fe5 */
2+
* Stub hash: eb6a3a2e3cf8f62e768d5d4968606438819e6cf0 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -1813,7 +1813,7 @@ ZEND_END_ARG_INFO()
18131813
#define arginfo_quoted_printable_encode arginfo_base64_encode
18141814

18151815
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mt_srand, 0, 0, IS_VOID, 0)
1816-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, seed, IS_LONG, 0, "0")
1816+
ZEND_ARG_TYPE_INFO(0, seed, IS_LONG, 0)
18171817
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_LONG, 0, "MT_RAND_MT19937")
18181818
ZEND_END_ARG_INFO()
18191819

ext/standard/tests/general_functions/rand.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ var_dump(rand(0,3));
1313

1414
var_dump(srand());
1515
var_dump(srand(-1));
16+
try {
17+
srand(mode: MT_RAND_MT19937);
18+
} catch (Error $e) {
19+
echo $e->getMessage() . "\n";
20+
}
1621

1722
var_dump(mt_srand());
1823
var_dump(mt_srand(-1));
1924

25+
try {
26+
mt_srand(mode: MT_RAND_MT19937);
27+
} catch (Error $e) {
28+
echo $e->getMessage() . "\n";
29+
}
30+
2031
var_dump(getrandmax());
2132

2233
var_dump(mt_getrandmax());
@@ -32,8 +43,10 @@ int(%i)
3243
int(%d)
3344
NULL
3445
NULL
46+
srand(): Argument #1 ($seed) must be passed explicitly, because the default value is not known
3547
NULL
3648
NULL
49+
mt_srand(): Argument #1 ($seed) must be passed explicitly, because the default value is not known
3750
int(%d)
3851
int(%d)
3952
Done

0 commit comments

Comments
 (0)