1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-23 23:32:18 +01:00

Fixed #4800: Check examples in the 'random' section of the manual

This commit is contained in:
Derick Rethans
2025-08-04 16:40:42 +01:00
parent a19139232a
commit 1bcc40f813
9 changed files with 32 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<book xml:id="book.random" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<book xml:id="book.random" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="interactive">
<?phpdoc extension-membership="core" ?>
<title>Random Number Generators and Functions Related to Randomness</title>
<titleabbrev>Random</titleabbrev>

View File

@@ -6,16 +6,38 @@
<programlisting role="php">
<![CDATA[
<?php
$r = new \Random\Randomizer();
/* ... */
// Generating a random domain name
printf(
"%s.example.com\n",
$r->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16)
);
// Shuffle array:
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
echo "Salad: ", implode(', ', $r->shuffleArray($fruits)), "\n";
// Shuffeling array keys
$fruits = [ 'red' => '🍎', 'green' => '🥝', 'yellow' => '🍌', 'pink' => '🍑', 'purple' => '🍇' ];
$keys = $r->pickArrayKeys($fruits, 2);
// Look up the values for the picked keys.
$selection = array_map(
static fn ($key) => $fruits[$key],
$keys
);
echo "Values: ", implode(', ', $selection), "\n";
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
...
j87fzv1p0daiwmlo.example.com
Salad: 🥝, 🍇, 🍎, 🍌, 🍑
Values: 🍌, 🍑
]]>
</screen>
</example>

View File

@@ -17,9 +17,6 @@
</para>
&caution.mt19937-tiny-seed;
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
@@ -77,7 +74,7 @@
<refsect1 role="examples">
&reftitle.examples;
<example>
<example annotations="non-interactive">
<title><function>Random\Engine\Mt19937::__construct</function> example</title>
<programlisting role="php">
<![CDATA[

View File

@@ -14,9 +14,6 @@
<para>
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
@@ -92,7 +89,7 @@
<refsect1 role="examples">
&reftitle.examples;
<example>
<example annotations="non-interactive">
<title><function>Random\Engine\PcgOneseq128XslRr64::__construct</function> example</title>
<programlisting role="php">
<![CDATA[

View File

@@ -14,9 +14,6 @@
<para>
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">
@@ -98,7 +95,7 @@
<refsect1 role="examples">
&reftitle.examples;
<example>
<example annotations="non-interactive">
<title><function>Random\Engine\Xoshiro256StarStar::__construct</function> example</title>
<programlisting role="php">
<![CDATA[

View File

@@ -37,37 +37,18 @@
</variablelist>
</refsect1>
<!-- Return values commented out, as constructors generally don't return a
value. Uncomment this if you do need a return values section (for
example, because there's also a procedural version of the method).
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
</para>
</refsect1>
-->
<refsect1 role="examples">
&reftitle.examples;
<example>
<example annotations="non-interactive">
<title><function>Random\Randomizer::__construct</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
/* ... */
$r = new \Random\Randomizer();
$r = new \Random\Randomizer(new \Random\Engine\Mt19937());
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
...
]]>
</screen>
</example>
</refsect1>

View File

@@ -15,9 +15,6 @@
<para>
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">

View File

@@ -14,9 +14,6 @@
<para>
</para>
&warn.undocumented.func;
</refsect1>
<refsect1 role="parameters">

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<book xml:id="book.reflection" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<book xml:id="book.reflection" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="interactive">
<?phpdoc extension-membership="core" ?>
<title>Reflection</title>
<titleabbrev>Reflection</titleabbrev>