Problem/Motivation

The REST Entity Display module in Drupal is generating multiple PHP deprecation warnings due to implicitly marking parameters as nullable. These warnings appear under PHP 8.4 and indicate that the module code needs to explicitly declare nullable types to comply with modern PHP standards. This results in log noise and potential compatibility issues with newer PHP versions.

Steps to reproduce

  1. Install REST Entity Display version 2.0.0 on a Drupal site running PHP 8.4 or higher.
  2. Enable full error reporting including deprecated notices (e.g., error_reporting(E_ALL | E_DEPRECATED)).
  3. Clear the Drupal cache using drush cr.
  4. Observe the PHP deprecation warnings in the logs or debug output, for example:
    • PHP Deprecated: Drupal\rest_entity_display_search_api_opensearch\Plugin\search_api\processor\RestEntityDisplayRenderedItem::getPropertyDefinitions(): Implicitly marking parameter $datasource as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rest_entity_display/rest_entity_display_search_api/src/Plugin/search_api/processor/RestEntityDisplayRenderedItem.php on line 126
    • PHP Deprecated: Drupal\rest_entity_display\EntityDisplayManagerInterface::getNormalizedEntityDisplay(): Implicitly marking parameter $langcode as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rest_entity_display/src/EntityDisplayManagerInterface.php on line 29
    • PHP Deprecated: Drupal\rest_entity_display\EntityDisplayManagerInterface::getNormalizedEntityDisplay(): Implicitly marking parameter $rendering_context as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/rest_entity_display/src/EntityDisplayManagerInterface.php on line 29

Proposed resolution

Update the REST Entity Display module to explicitly declare nullable types (e.g., ?Type) for all affected parameters. This includes:

  • RestEntityDisplayRenderedItem.php: Update getPropertyDefinitions($datasource) to explicitly mark $datasource as nullable.
  • EntityDisplayManagerInterface.php: Update getNormalizedEntityDisplay($langcode, $rendering_context) to explicitly mark $langcode and $rendering_context as nullable.

Implementing these changes will remove the deprecation warnings and ensure compatibility with PHP 8.4 and future versions.

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

johnatas created an issue. See original summary.

johnatas’s picture

Status: Active » Needs review

dom18fr made their first commit to this issue’s fork.

  • dom18fr committed 613b02f7 on 2.0.x authored by johnatas
    #3574571: Fix Multiple Implicit Nullable Parameters for PHP 8.4...
johnatas’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

johnatas’s picture

Status: Fixed » Closed (fixed)