Skip to content
Open
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
22 changes: 22 additions & 0 deletions language-snippets.ent
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ highly discouraged.</simpara></warning>'>
</para>
</caution>'>

<!ENTITY caution.mt19937-fork-unsafe '<caution xmlns="http://docbook.org/ns/docbook">
<para>
This method uses a lazy-initialized, global Mt19937 state.
</para>
<para>
If your code seeds the Mt19937 engine before <function>pcntl_fork</function>
(including indirectly via calls to
<function>rand</function>,
<function>mt_rand</function>,
<function>shuffle</function>,
<function>array_rand</function> or
<function>str_shuffle</function>),
forked children will inherit the parent seed and produce identical sequences.
</para>
<para>
If your code calls <function>pcntl_fork</function> without prior calls, every child will have a unique seed and produce a unique sequence.
</para>
<para>
Prefer using <classname>Random\Randomizer</classname> methods in all newly written code.
</para>
</caution>'>

<!ENTITY caution.mt19937-tiny-seed '<caution xmlns="http://docbook.org/ns/docbook">
<para>
Because the Mt19937 (“Mersenne Twister”) engine accepts only a single 32 bit integer as the
Expand Down
1 change: 1 addition & 0 deletions reference/array/functions/array-rand.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
key (or keys) of the random entries.
</para>
&caution.cryptographically-insecure;
&caution.mt19937-fork-unsafe;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
Expand Down
1 change: 1 addition & 0 deletions reference/array/functions/shuffle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
This function shuffles (randomizes the order of the elements in) an array.
</para>
&caution.cryptographically-insecure;
&caution.mt19937-fork-unsafe;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
Expand Down
21 changes: 21 additions & 0 deletions reference/pcntl/functions/pcntl-fork.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,27 @@ if ($pid == -1) {
</para>
</refsect1>

<refsect1 role="notes">
&reftitle.notes;
<caution>
<para>
The addition or removal of legacy random functions
(<function>srand</function>,
<function>mt_srand</function>,
<function>rand</function>,
<function>mt_rand</function>,
<function>shuffle</function>,
<function>array_rand</function> or
<function>str_shuffle</function>)
in any code executed prior to <function>pcntl_fork</function> can drastically
alter the behavior of these legacy random functions after forking.
</para>
<para>
Prefer using <classname>Random\Randomizer</classname> methods in all newly written code.
</para>
</caution>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
Expand Down
1 change: 1 addition & 0 deletions reference/random/functions/mt-rand.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
15)</literal>.
</simpara>
&caution.cryptographically-insecure;
&caution.mt19937-fork-unsafe;
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
Expand Down
1 change: 1 addition & 0 deletions reference/random/functions/mt-srand.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

&note.randomseed;
&caution.mt19937-tiny-seed;
&caution.mt19937-fork-unsafe;

</refsect1>
<refsect1 role="parameters">
Expand Down
1 change: 1 addition & 0 deletions reference/random/functions/rand.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
15)</literal>.
</simpara>
&caution.cryptographically-insecure;
&caution.mt19937-fork-unsafe;
<note>
<simpara>
Prior to PHP 7.1.0, <function>getrandmax</function> was only 32767 on some
Expand Down
1 change: 1 addition & 0 deletions reference/random/functions/srand.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

&note.randomseed;
&caution.mt19937-tiny-seed;
&caution.mt19937-fork-unsafe;
<note><simpara>As of PHP 7.1.0, <function>srand</function> has been made
an alias of <function>mt_srand</function>.</simpara>
</note>
Expand Down
1 change: 1 addition & 0 deletions reference/strings/functions/str-shuffle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
of all possible is created.
</simpara>
&caution.cryptographically-insecure;
&caution.mt19937-fork-unsafe;
</refsect1>

<refsect1 role="parameters">
Expand Down