Skip to content

random: Deprecate lcg_value() #15211

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
Aug 4, 2024
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 @@ -14,6 +14,9 @@ PHP NEWS
. array out of bounds, stack overflow handled for segfault handler on windows.
(David Carlier)

- Random:
. lcg_value() is now deprecated. (timwolla)

- Standard:
. Unserializing the uppercase 'S' tag is now deprecated. (timwolla)

Expand Down
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ PHP 8.4 UPGRADE NOTES
3-parameter signature with a null $row parameter instead.
. Added pg_result_memory_size to get the visibility the memory used by a query result.

- Random:
. lcg_value() is deprecated, as the function is broken in multiple ways.
Use \Random\Randomizer::getFloat() instead.
RFC: https://wiki.php.net/rfc/deprecations_php_8_4

- Reflection:
. Calling ReflectionMethod::__construct() with 1 argument is deprecated.
Use ReflectionMethod::createFromMethodName() instead.
Expand Down
1 change: 1 addition & 0 deletions ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "php.h"

#include "Zend/zend_attributes.h"
#include "Zend/zend_enum.h"
#include "Zend/zend_exceptions.h"

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 @@ -15,6 +15,7 @@
*/
const MT_RAND_PHP = UNKNOWN;

#[\Deprecated(since: '8.4', message: "use \\Random\\Randomizer::getFloat() instead")]
function lcg_value(): float {}

function mt_srand(?int $seed = null, int $mode = MT_RAND_MT19937): void {}
Expand Down
17 changes: 15 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.

2 changes: 1 addition & 1 deletion ext/random/tests/01_functions/lcg_value_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ echo "MATHS test script started\n";

echo "\n lcg_value tests...\n";
for ($i = 0; $i < 100; $i++) {
$res = lcg_value();
$res = @lcg_value();

if (!is_float($res) || $res < 0 || $res > 1) {
break;
Expand Down
11 changes: 11 additions & 0 deletions ext/random/tests/01_functions/lcg_value_deprecation.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
lcg_value() deprecation
--FILE--
<?php

var_dump(lcg_value());

?>
--EXPECTF--
Deprecated: Function lcg_value() is deprecated since 8.4, use \Random\Randomizer::getFloat() instead in %s on line %d
float(%f)
Loading