Problem/Motivation

The imagedestroy() function is deprecated as of PHP 8.5. Since PHP 8.0 the GD extension returns GdImage objects instead of resources, and these are freed automatically by the garbage collector, so imagedestroy() is now a no-op that only emits a deprecation notice.

The image_captcha submodule calls it in three places, each immediately followed by an unset($image) that already releases the reference:

  • modules/image_captcha/image_captcha.admin.inc, line 67
  • modules/image_captcha/src/Controller/CaptchaFontPreviewController.php, line 100
  • modules/image_captcha/src/Controller/CaptchaImageGeneratorController.php, line 144

Steps to reproduce

Run a PHPCompatibility scan over the module with a test version range that includes PHP 8.5:

phpcs --standard=PHPCompatibility --runtime-set testVersion 8.2- \
  --extensions=php,module,inc,install modules/image_captcha

Each of the three lines above is reported as: Function imagedestroy() is deprecated since PHP 8.5.

Proposed resolution

Remove the three imagedestroy($image); calls. Each is already followed by unset($image);, which drops the last reference and lets the object be collected, so behaviour is unchanged on PHP 8.0+ while the deprecation notice on PHP 8.5 goes away.

Issue fork captcha-3601310

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

pfrenssen’s picture

Status: Active » Needs review