mirror of
https://github.com/php/php-src.git
synced 2026-04-21 15:08:16 +02:00
54e406cc50
* Remove exception in Randomizer::shuffleBytes()
The only way that `php_binary_string_shuffle` fails is when the engine itself
fails. With the currently available list of engines we have:
- Mt19937 : Infallible.
- PcgOneseq128XslRr64: Infallible.
- Xoshiro256StarStar : Infallible.
- Secure : Practically infallible on modern systems.
Exception messages were cleaned up in GH-9169.
- User : Error when returning an empty string.
Error when seriously biased (range() fails).
And whatever Throwable the userland developer decides to use.
So the existing engines are either infallible or throw an Exception/Error with
a high quality message themselves, making this exception not a value-add and
possibly confusing.
* Remove exception in Randomizer::shuffleArray()
Same reasoning as in the previous commit applies.
* Remove exception in Randomizer::getInt()
Same reasoning as in the previous commit applies.
* Remove exception in Randomizer::nextInt()
Same reasoning as in the previous commit applies, except that it won't throw on
a seriously biased user engine, as `range()` is not used.
* Remove exception in Randomizer::getBytes()
Same reasoning as in the previous commit applies.
* Remove exception in Mt19937::generate()
This implementation is shared across all native engines. Thus the same
reasoning as the previous commits applies, except that the User engine does not
use this method. Thus is only applicable to the Secure engine, which is the
only fallible native engine.
* [ci skip] Add cleanup of Randomizer exceptions to NEWS
25 lines
516 B
PHP
25 lines
516 B
PHP
--TEST--
|
|
Random: Randomizer: User: Engine throws
|
|
--FILE--
|
|
<?php
|
|
|
|
$randomizer = (new \Random\Randomizer(
|
|
new class () implements \Random\Engine {
|
|
public function generate(): string
|
|
{
|
|
throw new Exception('Error');
|
|
}
|
|
}
|
|
));
|
|
|
|
var_dump($randomizer->getBytes(1));
|
|
|
|
?>
|
|
--EXPECTF--
|
|
Fatal error: Uncaught Exception: Error in %s:%d
|
|
Stack trace:
|
|
#0 [internal function]: Random\Engine@anonymous->generate()
|
|
#1 %s(%d): Random\Randomizer->getBytes(1)
|
|
#2 {main}
|
|
thrown in %s on line %d
|