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
- Install Drupal 10.6.x
- Enable PHP 8.4
- Install drupal/recaptcha 8.x-3.x
- 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.
Comments
Comment #3
shaikhshadab00Comment #4
dhendriks commentedI get the same error. Leads to HTTP 500 errors on website.
Comment #5
dhendriks commentedWith the patch from #3, it works again. Would be great if a bugfix release could be made with this patch in it.
Comment #6
ericvlThis issue was already mentioned here and fixed but no released yet.