mirror of
https://github.com/php/php-src.git
synced 2026-04-20 14:31:06 +02:00
When Radomizer::__construct() was called with no arguments, Randomizer\Engine\Secure was implicitly instantiate and memory was leaking. Co-authored-by: Tim Düsterhus <timwolla@googlemail.com>
41 lines
892 B
PHP
41 lines
892 B
PHP
--TEST--
|
|
Random: Randomizer: Disallow manually calling __construct
|
|
--FILE--
|
|
<?php
|
|
|
|
final class UserEngine implements \Random\Engine
|
|
{
|
|
public function generate(): string
|
|
{
|
|
return \random_byte(4); /* 32-bit */
|
|
}
|
|
}
|
|
|
|
try {
|
|
(new \Random\Randomizer())->__construct();
|
|
} catch (\BadMethodCallException $e) {
|
|
echo $e->getMessage() . PHP_EOL;
|
|
}
|
|
|
|
try {
|
|
$r = new \Random\Randomizer(new \Random\Engine\Xoshiro256StarStar());
|
|
$r->__construct(new \Random\Engine\PcgOneseq128XslRr64());
|
|
} catch (\BadMethodCallException $e) {
|
|
echo $e->getMessage() . PHP_EOL;
|
|
}
|
|
|
|
try {
|
|
$r = new \Random\Randomizer(new \UserEngine());
|
|
$r->__construct(new \UserEngine());
|
|
} catch (\BadMethodCallException $e) {
|
|
echo $e->getMessage() . PHP_EOL;
|
|
}
|
|
|
|
die('success');
|
|
?>
|
|
--EXPECT--
|
|
Cannot call constructor twice
|
|
Cannot call constructor twice
|
|
Cannot call constructor twice
|
|
success
|