Skip to content

Use ValueError if an invalid mode is passed to Mt19937 #9159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2022
Merged
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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ PHP NEWS
generating uniform integers within a given range). (timwolla)
. Fixed bug GH-9089 (Fix memory leak on Randomizer::__construct()
call twice) (zeriyoshi)
. Change Mt19937 to throw a ValueError instead of InvalidArgumentException
for invalid $mode. (timwolla)

- Sockets:
. Added SOL_FILTER socket option for Solaris. (David Carlier)
Expand Down
2 changes: 1 addition & 1 deletion ext/random/engine_mt19937.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ PHP_METHOD(Random_Engine_Mt19937, __construct)
state->mode = MT_RAND_PHP;
break;
default:
zend_argument_error(spl_ce_InvalidArgumentException, 2, "mode must be MT_RAND_MT19937 or MT_RAND_PHP");
zend_argument_value_error(2, "mode must be MT_RAND_MT19937 or MT_RAND_PHP");
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/random/tests/02_engine/mt19937_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Random: Engine: Mt19937: error pattern

try {
new \Random\Engine\Mt19937(1234, 2);
} catch (\InvalidArgumentException $e) {
echo $e->getMessage() . PHP_EOL;
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
Expand Down