chrisblakley/Nebula

PHP is deprecating rand() functions in PHP 8.3

chrisblakley opened this issue · 4 comments

Will need to find alternatives throughout Nebula and monitor vendor libraries for support as well.

https://wiki.php.net/rfc/deprecations_php_8_3#mt_rand_php

Screenshot 2023-05-29 at 7 53 07 PM

Seems like random_int() is the alternative now.

Locations in Nebula itself where these appear:

  • Admin.php
  • Utilities.php
  • Analytics.php
  • Shortcodes.php
  • Functions.php
  • metadata.php

Also appears in scssphp (x5) and plugin-update-checker (x2). There is an update available to the latter, but I doubt it addresses this quite yet.

Need to find an alternative to mt_getrandmax() as well which is used in metadata.php.

'?nocache' . mt_rand(1000, mt_getrandmax()) . '=debug' . mt_rand(1000, mt_getrandmax())

This is what I came up with:

'?nocache' . random_int(1000, PHP_INT_MAX) . '=debug' . random_int(1000, PHP_INT_MAX)

However, for this particular implementation I'll probably simplify to:

'?nocache' . random_int(100000, 999999) . '=debug' . random_int(100000, 999999)

Nebula has been updated, but still needs scssphp and plugin-update-checker to be updated before this can be closed.

Note that random_int() requires the libsodium package in PHP, so make sure that is always installed on servers.

Here is what vendor libraries are using:

  • mt_getrandmax() in scssphp in Compiler.php
  • mt_rand() in scssphp in Compiler.php several times
  • mt_rand() in PUC in OAuthSinature.php several times