Skip to content

Commit 3b7c653

Browse files
committed
Add a warning about the subtle global state in legacy random functions
Fixes php/php-src#21351 Replaces php/php-src#21352
1 parent 63bd68a commit 3b7c653

8 files changed

Lines changed: 17 additions & 0 deletions

File tree

language-snippets.ent

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ highly discouraged.</simpara></warning>'>
3131
</para>
3232
</caution>'>
3333

34+
<!ENTITY caution.subtle-global-state '<caution xmlns="http://docbook.org/ns/docbook">
35+
<simpara>
36+
This function shares a global state with other functions.
37+
These functions can alter each other's outputs, regardless of scope.
38+
</simpara>
39+
<simpara>
40+
Prefer using <classname>Random\Randomizer</classname> methods in all newly written code.
41+
</simpara>
42+
</caution>'>
43+
3444
<!ENTITY caution.mt19937-tiny-seed '<caution xmlns="http://docbook.org/ns/docbook">
3545
<para>
3646
Because the Mt19937 (“Mersenne Twister”) engine accepts only a single 32 bit integer as the

reference/array/functions/array-rand.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
key (or keys) of the random entries.
1818
</para>
1919
&caution.cryptographically-insecure;
20+
&caution.subtle-global-state;
2021
</refsect1>
2122
<refsect1 role="parameters">
2223
&reftitle.parameters;

reference/array/functions/shuffle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
This function shuffles (randomizes the order of the elements in) an array.
1616
</para>
1717
&caution.cryptographically-insecure;
18+
&caution.subtle-global-state;
1819
</refsect1>
1920
<refsect1 role="parameters">
2021
&reftitle.parameters;

reference/random/functions/mt-rand.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
15)</literal>.
3636
</simpara>
3737
&caution.cryptographically-insecure;
38+
&caution.subtle-global-state;
3839
</refsect1>
3940
<refsect1 role="parameters">
4041
&reftitle.parameters;

reference/random/functions/mt-srand.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
&note.randomseed;
2222
&caution.mt19937-tiny-seed;
23+
&caution.subtle-global-state;
2324

2425
</refsect1>
2526
<refsect1 role="parameters">

reference/random/functions/rand.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
15)</literal>.
2626
</simpara>
2727
&caution.cryptographically-insecure;
28+
&caution.subtle-global-state;
2829
<note>
2930
<simpara>
3031
Prior to PHP 7.1.0, <function>getrandmax</function> was only 32767 on some

reference/random/functions/srand.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
&note.randomseed;
2222
&caution.mt19937-tiny-seed;
23+
&caution.subtle-global-state;
2324
<note><simpara>As of PHP 7.1.0, <function>srand</function> has been made
2425
an alias of <function>mt_srand</function>.</simpara>
2526
</note>

reference/strings/functions/str-shuffle.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
of all possible is created.
1818
</simpara>
1919
&caution.cryptographically-insecure;
20+
&caution.subtle-global-state;
2021
</refsect1>
2122

2223
<refsect1 role="parameters">

0 commit comments

Comments
 (0)