Title

PHP 8.4 Compatibility: Fix Implicitly Nullable Parameter Deprecation in isViewing() Method

Description

PHP 8.4 deprecates implicitly nullable parameters where a typed parameter has a default value of
NULL without explicitly declaring the parameter as nullable.

The following method contains an implicitly nullable parameter:

public static function isViewing(EntityInterface $entity, RouteMatchInterface $route_match = NULL) {

This results in the following PHP 8.4 deprecation warning:

Deprecated: Implicitly marking parameter $route_match as nullable is deprecated,
the explicit nullable type must be used instead.

To ensure PHP 8.4 compatibility and remove the deprecation warning, the parameter type has been
updated to explicitly allow null.

Before

public static function isViewing(EntityInterface $entity, RouteMatchInterface $route_match = NULL) {

After

public static function isViewing(EntityInterface $entity, ?RouteMatchInterface $route_match = NULL) {

Benefits

  • Resolves PHP 8.4 deprecation warnings.
  • Ensures forward compatibility with future PHP versions.
  • Improves code clarity by explicitly indicating nullable parameters.
  • No functional changes to existing behaviour.

Issue Type

Code Quality / PHP 8.4 Compatibility

Impact

Low Risk. This is a non-functional change that updates the method signature to comply with
PHP 8.4 requirements while preserving existing behaviour.

Comments

imran2734 created an issue. See original summary.

imran2734’s picture

Status: Patch (to be ported) » Needs review