Problem/Motivation
Upgrade Status module reports the following PHP 8.4 deprecation problems for a D11 migration:
modules/contrib/captcha/modules/image_captcha/src/Service/ImageCaptchaRenderService.php 128 Call to deprecated function lcg_value().
modules/contrib/captcha/modules/image_captcha/src/Service/ImageCaptchaRenderService.php 129 Call to deprecated function lcg_value().
modules/contrib/captcha/modules/image_captcha/src/Service/ImageCaptchaRenderService.php 132 Call to deprecated function lcg_value().
modules/contrib/captcha/modules/image_captcha/src/Service/ImageCaptchaRenderService.php 133 Call to deprecated function lcg_value().
Steps to reproduce
Install the upgrade_status module on 10.x site with Captcha installed..
Scan the captcha module
See https://www.php.net/manual/en/function.lcg-value.php
Proposed resolution
Change the lcg_value calls to use the Random extension. E.g:
$randomizer = new Random\Randomizer();
$random_float = $randomizer->getFloat();
Note this was added in PHP 8.2. But since PHP 8.1 officially reached End of Life (EOL) on December 31, 2025 this shouldn't be a blocker.
Remaining tasks
Make changes
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comments
Comment #2
cgmonroe commentedHere's a patch to remove the deprecated calls
Comment #3
anybody@cgmonroe could you please provide this as MR, not patch? Thanks!
Comment #5
anybodyComment #6
lfersoy commentedPatch confirmed. +1 RTBC
Comment #7
anybodyComment #8
anybodyStill needs someone to set it RTBC once reviewed.
Comment #9
herved commentedThere are also other deprecations for 8.5, like imagedestroy(), but maybe that should be a followup?
Comment #10
anybody@herved yes I think let's do that separately.
Comment #11
csakiistvanEnvironment
drupal/captcha: 2.0.10Step 1 — Install the module
Step 2 — Enable distortion to trigger the affected code path
The
lcg_value()calls only execute whenimage_captcha_distortion_amplitudeis greater than 1:ddev drush config:set image_captcha.settings image_captcha_distortion_amplitude 5 -yStep 3 — Apply the fix from MR !131
In
modules/image_captcha/src/Service/ImageCaptchaRenderService.php, replace the fourlcg_value()calls with\Random\Randomizer:Step 4 — Verify the fix
Syntax check:
ddev exec php -l web/modules/contrib/captcha/modules/image_captcha/src/Service/ImageCaptchaRenderService.phpExpected:
No syntax errors detectedConfirm the image endpoint returns a valid image:
curl -s -o /dev/null -w "%{http_code} %{content_type}" https://tester.ddev.site/image-captcha-generate/{session_id}/{timestamp}Expected:
200 image/jpegResults
lcg_value()calls replaced with\Random\Randomizer::getFloat()The fix works correctly.
\Random\Randomizer::getFloat()is available since PHP 8.2 and is the appropriate replacement for the deprecatedlcg_value().This comment was produced with the assistance of an LLM
Comment #12
anybodyThanks, merged into dev to push things forward here. Could we please have a separate follow-up for #9?
Comment #13
anybodyComment #16
pfrenssenCreated followup to address #9: #3601310: Remove deprecated calls to imagedestroy()
Comment #17
hoporr commented(issue was closed, cannot reopen, so I created a second issue with this text)
Captcha 2.0.10:
Drupal core 11.3.13
PHP 8.4
1) Tried to install the MR patch, and it failed.
2) I then installed the patch from #2, and am getting this error when the captcha is supposed to be rendered (also on the image_captcha config page):
ParseError: syntax error, unexpected token ".", expecting identifier or variable or "{" or "$" in {closure:Composer\Autoload\ClassLoader::initializeIncludeClosure():575}() (Zeile 131 in /...../www/modules/contrib/captcha/modules/image_captcha/src/Service/ImageCaptchaRenderService.php).
The patch applied like this -- note the '.' in front of "getFloat" , so yes here is a problem:
$wavelength_yr = (2 + 3 * $randomizer->.getFloat(0, 1)) * $font_size;
I then inspected the actual patches, and noticed this:
patch #2 actually has the error in it, note the '.' :
+ $wavelength_yr = (2 + 3 * $randomizer->.getFloat(0, 1)) * $font_size;
In the MR, the line is correct:
+ $wavelength_yr = (2 + 3 * $randomizer->getFloat(0, 1)) * $font_size;
But the MR fails to install for me.