From 5b372788a46fdc82f8215c63ce4598e7b951e57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 29 Jun 2023 19:45:46 +0200 Subject: [PATCH 1/2] Deprecate MT_RAND_PHP see https://wiki.php.net/rfc/deprecations_php_8_3#mt_rand_php --- ext/random/engine_mt19937.c | 1 + ext/random/random.c | 5 +++++ ext/random/random.stub.php | 1 + ext/random/random_arginfo.h | 4 ++-- .../tests/01_functions/array_rand_mt_rand_php.phpt | 3 +++ ext/random/tests/01_functions/bug75514.phpt | 5 ++++- ext/random/tests/01_functions/mt_rand_value.phpt | 5 ++++- .../tests/03_randomizer/compatibility_mt_rand.phpt | 10 +++++++++- ext/random/tests/03_randomizer/methods/getBytes.phpt | 5 ++++- .../03_randomizer/methods/getBytesFromString.phpt | 5 ++++- ext/random/tests/03_randomizer/methods/getFloat.phpt | 5 ++++- ext/random/tests/03_randomizer/methods/getInt.phpt | 5 ++++- ext/random/tests/03_randomizer/methods/nextFloat.phpt | 5 ++++- ext/random/tests/03_randomizer/methods/nextInt.phpt | 5 ++++- .../tests/03_randomizer/methods/pickArrayKeys.phpt | 5 ++++- .../tests/03_randomizer/methods/shuffleArray.phpt | 5 ++++- .../tests/03_randomizer/methods/shuffleBytes.phpt | 5 ++++- ext/random/tests/03_randomizer/serialize.phpt | 5 ++++- 18 files changed, 69 insertions(+), 15 deletions(-) diff --git a/ext/random/engine_mt19937.c b/ext/random/engine_mt19937.c index 87f96be70abd8..e16c9f6722fc3 100644 --- a/ext/random/engine_mt19937.c +++ b/ext/random/engine_mt19937.c @@ -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: diff --git a/ext/random/random.c b/ext/random/random.c index d67b82c0713a7..f34d55f340727 100644 --- a/ext/random/random.c +++ b/ext/random/random.c @@ -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 { diff --git a/ext/random/random.stub.php b/ext/random/random.stub.php index d03057d7a6a6e..1b40294e60f41 100644 --- a/ext/random/random.stub.php +++ b/ext/random/random.stub.php @@ -10,6 +10,7 @@ const MT_RAND_MT19937 = UNKNOWN; /** * @var int + * @deprecated * @cvalue MT_RAND_PHP */ const MT_RAND_PHP = UNKNOWN; diff --git a/ext/random/random_arginfo.h b/ext/random/random_arginfo.h index 967dd2d2eb290..6b5f8a82c4b68 100644 --- a/ext/random/random_arginfo.h +++ b/ext/random/random_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 533dc78162cc1e510f7c87971a6350acd43de1ab */ + * Stub hash: 35cb16abb3392bd257a43cc675cad4f5af5549c1 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_lcg_value, 0, 0, IS_DOUBLE, 0) ZEND_END_ARG_INFO() @@ -259,7 +259,7 @@ static const zend_function_entry class_Random_RandomException_methods[] = { static void register_random_symbols(int module_number) { REGISTER_LONG_CONSTANT("MT_RAND_MT19937", MT_RAND_MT19937, CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("MT_RAND_PHP", MT_RAND_PHP, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("MT_RAND_PHP", MT_RAND_PHP, CONST_PERSISTENT | CONST_DEPRECATED); } static zend_class_entry *register_class_Random_Engine_Mt19937(zend_class_entry *class_entry_Random_Engine) diff --git a/ext/random/tests/01_functions/array_rand_mt_rand_php.phpt b/ext/random/tests/01_functions/array_rand_mt_rand_php.phpt index 01a4e3ff5dfcd..703460a890f05 100644 --- a/ext/random/tests/01_functions/array_rand_mt_rand_php.phpt +++ b/ext/random/tests/01_functions/array_rand_mt_rand_php.phpt @@ -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" diff --git a/ext/random/tests/01_functions/bug75514.phpt b/ext/random/tests/01_functions/bug75514.phpt index da77b9bd9b1f4..583ac9a209ef3 100644 --- a/ext/random/tests/01_functions/bug75514.phpt +++ b/ext/random/tests/01_functions/bug75514.phpt @@ -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) diff --git a/ext/random/tests/01_functions/mt_rand_value.phpt b/ext/random/tests/01_functions/mt_rand_value.phpt index ab6d732709b13..ede620648e16b 100644 --- a/ext/random/tests/01_functions/mt_rand_value.phpt +++ b/ext/random/tests/01_functions/mt_rand_value.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/compatibility_mt_rand.phpt b/ext/random/tests/03_randomizer/compatibility_mt_rand.phpt index a69c50d0cb622..4abb1276f3665 100644 --- a/ext/random/tests/03_randomizer/compatibility_mt_rand.phpt +++ b/ext/random/tests/03_randomizer/compatibility_mt_rand.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/getBytes.phpt b/ext/random/tests/03_randomizer/methods/getBytes.phpt index a236e9746fa19..d4fbf7c7c8ca9 100644 --- a/ext/random/tests/03_randomizer/methods/getBytes.phpt +++ b/ext/random/tests/03_randomizer/methods/getBytes.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/getBytesFromString.phpt b/ext/random/tests/03_randomizer/methods/getBytesFromString.phpt index 7ee7d990adff7..6a36d20543222 100644 --- a/ext/random/tests/03_randomizer/methods/getBytesFromString.phpt +++ b/ext/random/tests/03_randomizer/methods/getBytesFromString.phpt @@ -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" diff --git a/ext/random/tests/03_randomizer/methods/getFloat.phpt b/ext/random/tests/03_randomizer/methods/getFloat.phpt index 1fcec7f3e223a..a7966ed37c1df 100644 --- a/ext/random/tests/03_randomizer/methods/getFloat.phpt +++ b/ext/random/tests/03_randomizer/methods/getFloat.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/getInt.phpt b/ext/random/tests/03_randomizer/methods/getInt.phpt index faa098ade1364..5193d1d52f77c 100644 --- a/ext/random/tests/03_randomizer/methods/getInt.phpt +++ b/ext/random/tests/03_randomizer/methods/getInt.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/nextFloat.phpt b/ext/random/tests/03_randomizer/methods/nextFloat.phpt index 4a583d00e78d9..49c2ec573a28a 100644 --- a/ext/random/tests/03_randomizer/methods/nextFloat.phpt +++ b/ext/random/tests/03_randomizer/methods/nextFloat.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/nextInt.phpt b/ext/random/tests/03_randomizer/methods/nextInt.phpt index fd4460cb811ce..008e5acb259e8 100644 --- a/ext/random/tests/03_randomizer/methods/nextInt.phpt +++ b/ext/random/tests/03_randomizer/methods/nextInt.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/pickArrayKeys.phpt b/ext/random/tests/03_randomizer/methods/pickArrayKeys.phpt index 4178455898df4..e79403ce0b5fa 100644 --- a/ext/random/tests/03_randomizer/methods/pickArrayKeys.phpt +++ b/ext/random/tests/03_randomizer/methods/pickArrayKeys.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/shuffleArray.phpt b/ext/random/tests/03_randomizer/methods/shuffleArray.phpt index c0f6d17fecddf..73e5649d8fb64 100644 --- a/ext/random/tests/03_randomizer/methods/shuffleArray.phpt +++ b/ext/random/tests/03_randomizer/methods/shuffleArray.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/methods/shuffleBytes.phpt b/ext/random/tests/03_randomizer/methods/shuffleBytes.phpt index d16168d32fe2d..026c3eb45664d 100644 --- a/ext/random/tests/03_randomizer/methods/shuffleBytes.phpt +++ b/ext/random/tests/03_randomizer/methods/shuffleBytes.phpt @@ -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 diff --git a/ext/random/tests/03_randomizer/serialize.phpt b/ext/random/tests/03_randomizer/serialize.phpt index b02bb93c827b3..4d78433c00f5a 100644 --- a/ext/random/tests/03_randomizer/serialize.phpt +++ b/ext/random/tests/03_randomizer/serialize.phpt @@ -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 From 6b6c4d3021c4dd50275f96c495d23bf3501d444a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 7 Jul 2023 12:16:12 +0200 Subject: [PATCH 2/2] [ci skip] NEWS / UPGRADING for MT_RAND_PHP deprecation --- NEWS | 3 +++ UPGRADING | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 0bb5fe988a589..76c0e14d1f4e4 100644 --- a/NEWS +++ b/NEWS @@ -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: diff --git a/UPGRADING b/UPGRADING index e0e35c3613bbf..1aad94d4ce4f7 100644 --- a/UPGRADING +++ b/UPGRADING @@ -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