Problem

Running Drupal 10.6.x with PHP 8.4 causes a fatal error on page load:

Fatal error: Declaration of Drupal\recaptcha\ReCaptcha\RequestMethod\Drupal8Post::submit(
  ReCaptcha\RequestParameters $params
) must be compatible with ReCaptcha\RequestMethod::submit(
  ReCaptcha\RequestParameters $params
): string in Drupal8Post.php on line 39

PHP 8.4 enforces return type declarations on methods that implement
an interface. The RequestMethod interface declares submit() with
a : string return type, but Drupal8Post::submit() omits it.

Steps to reproduce

  1. Install Drupal 10.6.x
  2. Enable PHP 8.4
  3. Install drupal/recaptcha 8.x-3.x
  4. Visit any page — fatal error is thrown immediately

Environment

  • Drupal: 10.6.x
  • PHP: 8.4.x
  • Module: drupal/recaptcha 8.x-3.4
  • Server: nginx / platform.sh

Proposed fix

In src/ReCaptcha/RequestMethod/Drupal8Post.php line ~39:

// Before
public function submit(RequestParameters $params)

// After
public function submit(RequestParameters $params): string

A merge request with this fix is attached.

CommentFileSizeAuthor
#3 recaptcha-php84-return-type.patch525 bytesshaikhshadab00

Issue fork recaptcha-3590405

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

shaikhshadab00 created an issue. See original summary.

shaikhshadab00 changed the visibility of the branch 3590405-php-8.4-drupal8postsubmit to hidden.

shaikhshadab00’s picture

StatusFileSize
new525 bytes
dhendriks’s picture

I get the same error. Leads to HTTP 500 errors on website.

dhendriks’s picture

With the patch from #3, it works again. Would be great if a bugfix release could be made with this patch in it.

ericvl’s picture

Related issues: +#3588269: PHP 8.4 bug fix

This issue was already mentioned here and fixed but no released yet.