Skip to content

Commit f5f9294

Browse files
authored
random: Deprecate lcg_value() (#15211)
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
1 parent ecd11b9 commit f5f9294

File tree

7 files changed

+37
-3
lines changed

7 files changed

+37
-3
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ PHP NEWS
1414
. array out of bounds, stack overflow handled for segfault handler on windows.
1515
(David Carlier)
1616

17+
- Random:
18+
. lcg_value() is now deprecated. (timwolla)
19+
1720
- Standard:
1821
. Unserializing the uppercase 'S' tag is now deprecated. (timwolla)
1922

UPGRADING

+5
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ PHP 8.4 UPGRADE NOTES
434434
3-parameter signature with a null $row parameter instead.
435435
. Added pg_result_memory_size to get the visibility the memory used by a query result.
436436

437+
- Random:
438+
. lcg_value() is deprecated, as the function is broken in multiple ways.
439+
Use \Random\Randomizer::getFloat() instead.
440+
RFC: https://wiki.php.net/rfc/deprecations_php_8_4
441+
437442
- Reflection:
438443
. Calling ReflectionMethod::__construct() with 1 argument is deprecated.
439444
Use ReflectionMethod::createFromMethodName() instead.

ext/random/random.c

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "php.h"
2929

30+
#include "Zend/zend_attributes.h"
3031
#include "Zend/zend_enum.h"
3132
#include "Zend/zend_exceptions.h"
3233

ext/random/random.stub.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
const MT_RAND_PHP = UNKNOWN;
1717

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

2021
function mt_srand(?int $seed = null, int $mode = MT_RAND_MT19937): void {}

ext/random/random_arginfo.h

+15-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/random/tests/01_functions/lcg_value_basic.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo "MATHS test script started\n";
88

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

1313
if (!is_float($res) || $res < 0 || $res > 1) {
1414
break;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
lcg_value() deprecation
3+
--FILE--
4+
<?php
5+
6+
var_dump(lcg_value());
7+
8+
?>
9+
--EXPECTF--
10+
Deprecated: Function lcg_value() is deprecated since 8.4, use \Random\Randomizer::getFloat() instead in %s on line %d
11+
float(%f)

0 commit comments

Comments
 (0)