Fix Multiple Implicit Nullable Parameters for PHP 8.4 Compatibility

Created on 29 March 2025, 21 days ago

Problem/Motivation

The Rabbit Hole module in Drupal is generating multiple PHP deprecation warnings related to implicitly marking parameters as nullable. These warnings indicate that the codebase needs to be updated to use explicit nullable types to comply with modern PHP standards. This is causing noise in logs and potential compatibility issues with newer PHP versions.

Steps to reproduce

  1. Install the Rabbit Hole module in a Drupal environment running PHP 8.4 or higher.
  2. Enable deprecated error logging in PHP configuration (e.g., error_reporting(E_ALL | E_DEPRECATED)).
  3. Clear cache with drush cr or Trigger actions or settings forms related to the Rabbit Hole module (e.g., configure a redirect, access denied, or page not found behavior).
  4. Check the PHP error logs or debug output to observe the deprecation warnings listed below:
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\PageRedirect::performAction(): Implicitly marking parameter $current_response as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php on line 117
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\PageRedirect::settingsForm(): Implicitly marking parameter $entity as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php on line 253
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\PageRedirect::settingsForm(): Implicitly marking parameter $bundle_settings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPlugin/PageRedirect.php on line 253
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginBase::settingsForm(): Implicitly marking parameter $entity as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPluginBase.php on line 28
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginBase::settingsForm(): Implicitly marking parameter $bundle_settings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPluginBase.php on line 28
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginInterface::settingsForm(): Implicitly marking parameter $entity as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPluginInterface.php on line 44
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPluginInterface::settingsForm(): Implicitly marking parameter $bundle_settings as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPluginInterface.php on line 44
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\AccessDenied::performAction(): Implicitly marking parameter $current_response as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPlugin/AccessDenied.php on line 23
    • PHP Deprecated: Drupal\rabbit_hole\Plugin\RabbitHoleBehaviorPlugin\PageNotFound::performAction(): Implicitly marking parameter $current_response as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rabbit_hole/src/Plugin/RabbitHoleBehaviorPlugin/PageNotFound.php on line 23

Proposed resolution

Update the Rabbit Hole module's codebase to use explicit nullable types (e.g., ?Type) for the affected parameters in the following files and methods:

  • PageRedirect.php: Update performAction($current_response) and settingsForm($entity, $bundle_settings).
  • RabbitHoleBehaviorPluginBase.php: Update settingsForm($entity, $bundle_settings).
  • RabbitHoleBehaviorPluginInterface.php: Update settingsForm($entity, $bundle_settings).
  • AccessDenied.php: Update performAction($current_response).
  • PageNotFound.php: Update performAction($current_response).

This will eliminate the deprecation warnings and ensure compatibility with PHP standards moving forward.

Remaining tasks

  • Implement the proposed changes in the module's source code.
  • Test the updated module to ensure functionality remains intact (e.g., redirects, access denied, and page not found behaviors).
🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇮🇳India DhruvR

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024