Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Düsterhus <[email protected]>
  • Loading branch information
saundefined and TimWolla committed Sep 26, 2023
1 parent 133bc45 commit b7555d6
Showing 1 changed file with 86 additions and 26 deletions.
112 changes: 86 additions & 26 deletions releases/8.3/release.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ PHP
</div>

<div class="php8-compare">
<h2 class="php8-h2" id="dnf_types">
<h2 class="php8-h2" id="typed_class_constants">
Typed class constants
<a class="php8-rfc" href="https://wiki.php.net/rfc/typed_class_constants">RFC</a>
</h2>
Expand Down Expand Up @@ -100,7 +100,7 @@ PHP
</div>

<div class="php8-compare">
<h2 class="php8-h2" id="null_false_true_types">
<h2 class="php8-h2" id="override_attribute">
<code>#[Override]</code> attribute
<a class="php8-rfc" href="https://wiki.php.net/rfc/marking_overriden_methods">RFC</a>
</h2>
Expand Down Expand Up @@ -131,17 +131,35 @@ PHP
</div>

<div class="php8-compare">
<h2 class="php8-h2" id="null_false_true_types">
<code>Randomizer</code> additions
<a class="php8-rfc" href="https://wiki.php.net/rfc/randomizer_additions">RFC</a>
<h2 class="php8-h2" id="randomizer_get_bytes_from_string">
New <code>Randomizer::getBytesFromString</code> method
<a class="php8-rfc" href="https://wiki.php.net/rfc/randomizer_additions#getbytesfromstring">RFC</a>
</h2>
<div class="php8-compare__main">
<div class="php8-compare__block example-contents">
<div class="php8-compare__label">PHP &lt; 8.3</div>
<div class="php8-code phpcode">
<?php highlight_php_trimmed(
<<<'PHP'
// TODO
// This function needs to be manually implemented.
function getBytesFromString(string $string, int $length) {
$stringLength = strlen($string);
$result = '';
for ($i = 0; $i < $length; $i++) {
// random_int is not seedable for testing, but secure.
$result .= $string[random_int(0, $stringLength - 1)]);
}
return $result;
}
$randomDomain = sprintf(
"%s.example.com",
getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16),
);
echo $randomDomain;
PHP

); ?>
Expand All @@ -153,7 +171,15 @@ PHP
<div class="php8-code phpcode">
<?php highlight_php_trimmed(
<<<'PHP'
// TODO
// A \Random\Engine may be passed for seeding, the default is the secure engine.
$randomizer = new \Random\Randomizer();
$randomDomain = sprintf(
"%s.example.com",
$randomizer->getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16),
);
echo $randomDomain;
PHP
); ?>
</div>
Expand All @@ -162,17 +188,30 @@ PHP
</div>

<div class="php8-compare">
<h2 class="php8-h2" id="null_false_true_types">
Dynamic class constant fetch
<a class="php8-rfc" href="https://wiki.php.net/rfc/dynamic_class_constant_fetch">RFC</a>
<h2 class="php8-h2" id="randomizer_get_float">
New <code>Randomizer::getFloat</code> and <code>Randomizer::nextFloat</code> methods
<a class="php8-rfc" href="https://wiki.php.net/rfc/randomizer_additions#getfloat">RFC</a>
</h2>
<div class="php8-compare__main">
<div class="php8-compare__block example-contents">
<div class="php8-compare__label">PHP &lt; 8.3</div>
<div class="php8-code phpcode">
<?php highlight_php_trimmed(
<<<'PHP'
// TODO
// Returns a random float between $min and $max, both including.
function getFloat(float $min, float $max) {
// This algorithm is biased for specific inputs and may
// return values outside the given range. This is impossible
// to work around in userland.
return (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) * ($max - $min) + $min;
}
$temperature = getFloat(-89.2, 56.7);
$chanceForTrue = 0.1;
// getFloat(0, 1) might return the upper bound, i.e. 1,
// introducing a small bias.
$myBoolean = getFloat(0, 1) < $chanceForTrue;
PHP

); ?>
Expand All @@ -184,18 +223,32 @@ PHP
<div class="php8-code phpcode">
<?php highlight_php_trimmed(
<<<'PHP'
// TODO
$randomizer = new \Random\Randomizer();
$temperature = $randomizer->getFloat(-89.2, 56.7, \Random\IntervalBoundary::ClosedClosed);
$chanceForTrue = 0.1;
// Randomizer::nextFloat() is equivalent to Randomizer::getFloat(0, 1, \Random\IntervalBoundary::ClosedOpen).
// The upper bound, i.e. 1, will not be returned.
$myBoolean = $randomizer->nextFloat(); < $chanceForTrue;
PHP
); ?>
</div>
</div>
</div>
</div>

<div class="php8-compare__content">
The algorithm used is the γ-section algorithm as published in:
<a href="https://doi.org/10.1145/3503512" target="_blank" rel="noopener noreferrer">Drawing Random
Floating-Point Numbers from an Interval</a>.
Frédéric Goualard, ACM Trans. Model. Comput. Simul., 32:3, 2022.
</div>

<div class="php8-compare">
<h2 class="php8-h2" id="null_false_true_types">
Improved <code>unserialize()</code> error handling
<a class="php8-rfc" href="https://wiki.php.net/rfc/improve_unserialize_error_handling">RFC</a>
<h2 class="php8-h2" id="dynamic_class_constant_fetch">
Dynamic class constant fetch
<a class="php8-rfc" href="https://wiki.php.net/rfc/dynamic_class_constant_fetch">RFC</a>
</h2>
<div class="php8-compare__main">
<div class="php8-compare__block example-contents">
Expand Down Expand Up @@ -229,11 +282,18 @@ PHP
<h2 class="php8-h2" id="other_new_things"><?= message('new_classes_title', $lang) ?></h2>
<div class="php8-compare__content php8-compare__content--block">
<ul>
<li>New <code>json_validate</code> function</li>
<li>New <code>mb_str_pad</code> function</li>
<li>New <code>posix_sysconf</code>, <code>posix_pathconf</code>, <code>posix_fpathconf</code>, and <code>posix_eaccess</code> functions</li>
<li>New <code>Randomizer::getBytesFromString</code>, <code>Randomizer::nextFloat</code>, and <code>Randomizer::getFloat</code> functions, also <code>Randomizer::IntervalBoundary</code> enum.</li>
<li>New <code>json_validate</code> function.</li>
<li>New <code>ldap_connect_wallet</code>, and <code>ldap_exop_sync</code> functions.</li>
<li>New <code>mb_str_pad</code> function.</li>
<li>New <code>posix_sysconf</code>, <code>posix_pathconf</code>, <code>posix_fpathconf</code>, and
<code>posix_eaccess</code> functions.
</li>
<li>New <code>ReflectionMethod::createFromMethodName</code> method.</li>
<li>New <code>socket_atmark</code> function.</li>
<li>New <code>str_increment</code>, <code>str_decrement</code>, and
<code>stream_context_set_options</code> functions.
</li>
<li>New <code>ZipArchive::getArchiveFlag</code> function.</li>
</ul>
</div>
</div>
Expand All @@ -242,13 +302,13 @@ PHP
<h2 class="php8-h2" id="deprecations_and_bc_breaks"><?= message('bc_title', $lang) ?></h2>
<div class="php8-compare__content">
<ul>
<li>More Appropriate Date/Time Exceptions</li>
<li>Negative indices in arrays</li>
<li>Changes to the <code>range</code> function</li>
<li>Traits and static properties</li>
<li>The <code>U_MULTIPLE_DECIMAL_SEPERATORS</code> constant had been deprecated in favor of <code>U_MULTIPLE_DECIMAL_SEPARATORS</code></li>
<li>Changed <code>mt_srand</code> and <code>srand</code> functions</li>
<li><code>ReflectionClass::getStaticProperties</code> is no longer nullable</li>
<li>More Appropriate Date/Time Exceptions.</li>
<li>Negative indices in arrays.</li>
<li>Changes to the <code>range</code> function.</li>
<li>Traits and static properties.</li>
<li>The <code>U_MULTIPLE_DECIMAL_SEPERATORS</code> constant had been deprecated in favor of <code>U_MULTIPLE_DECIMAL_SEPARATORS</code>.</li>
<li>The <code>MT_RAND_PHP</code> Mt19937 variant is deprecated.</li>
<li><code>ReflectionClass::getStaticProperties</code> is no longer nullable.</li>
</ul>
</div>
</div>
Expand Down

0 comments on commit b7555d6

Please sign in to comment.