Skip to content

Deprecate MT_RAND_PHP #11560

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 4 commits into from
Jul 7, 2023
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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ PHP NEWS
- OpenSSL
. Added support for additional EC parameters in openssl_pkey_new. (Eno-CN)

- Random
. Deprecate MT_RAND_PHP. (timwolla)

06 Jul 2023, PHP 8.3.0alpha3

- Core:
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ PHP 8.3 UPGRADE NOTES
. The U_MULTIPLE_DECIMAL_SEP*E*RATORS constant had been deprecated, using
the U_MULTIPLE_DECIMAL_SEP*A*RATORS instead is recommended.

- Random
. The MT_RAND_PHP Mt19937 variant is deprecated.
RFC: https://wiki.php.net/rfc/deprecations_php_8_3#mt_rand_php

- SQLite3
. Using exceptions is now preferred, warnings will be removed in the future.
Calling SQLite3::enableExceptions(false) will trigger a depreciation warning
Expand Down
1 change: 1 addition & 0 deletions ext/random/engine_mt19937.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ PHP_METHOD(Random_Engine_Mt19937, __construct)
state->mode = MT_RAND_MT19937;
break;
case MT_RAND_PHP:
zend_error(E_DEPRECATED, "The MT_RAND_PHP variant of Mt19937 is deprecated");
state->mode = MT_RAND_PHP;
break;
default:
Expand Down
5 changes: 5 additions & 0 deletions ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ PHP_FUNCTION(mt_srand)

state->mode = mode;

/* Anything that is not MT_RAND_MT19937 was interpreted as MT_RAND_PHP. */
if (state->mode != MT_RAND_MT19937) {
zend_error(E_DEPRECATED, "The MT_RAND_PHP variant of Mt19937 is deprecated");
}

if (seed_is_null) {
php_random_mt19937_seed_default(status->state);
} else {
Expand Down
1 change: 1 addition & 0 deletions ext/random/random.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
const MT_RAND_MT19937 = UNKNOWN;
/**
* @var int
* @deprecated
* @cvalue MT_RAND_PHP
*/
const MT_RAND_PHP = UNKNOWN;
Expand Down
4 changes: 2 additions & 2 deletions ext/random/random_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ext/random/tests/01_functions/array_rand_mt_rand_php.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var_dump(
);
?>
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
string(11) "found key 0"
string(11) "found key 1"
string(11) "found key 0"
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/01_functions/bug75514.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Bug #75514 mt_rand returns value outside [$min,$max]
mt_srand(0, MT_RAND_PHP);
var_dump(mt_rand(0,999999999), mt_rand(0,999));
?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
int(448865905)
int(592)
5 changes: 4 additions & 1 deletion ext/random/tests/01_functions/mt_rand_value.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ echo $x.PHP_EOL;
*/

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
1614640687
1711027313
857485497
Expand Down
10 changes: 9 additions & 1 deletion ext/random/tests/03_randomizer/compatibility_mt_rand.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ for ($i = 0; $i < 10_000; $i++) {
die('success');

?>
--EXPECT--
--EXPECTF--
MT_RAND_PHP

Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d

Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
MT_RAND_MT19937
success
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/getBytes.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
string(10) "aaaaaaaaaa"
string(5) "aaaaa"
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/getFloat.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/getInt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/nextFloat.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/nextInt.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/pickArrayKeys.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/shuffleArray.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/methods/shuffleBytes.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ foreach ($engines as $engine) {
die('success');

?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down
5 changes: 4 additions & 1 deletion ext/random/tests/03_randomizer/serialize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ foreach ($engines as $engine) {

die('success');
?>
--EXPECT--
--EXPECTF--
Deprecated: Constant MT_RAND_PHP is deprecated in %s on line %d

Deprecated: The MT_RAND_PHP variant of Mt19937 is deprecated in %s on line %d
Random\Engine\Mt19937
Random\Engine\Mt19937
Random\Engine\PcgOneseq128XslRr64
Expand Down