Problem/Motivation

PHP 8.4 deprecates implicitly nullable parameter types. When a typed parameter
has a default value of NULL without an explicit ? prefix on the type hint,
PHP 8.4 emits a deprecation warning.

In EntityConflictDiscoveryEvent::__construct(), the $context parameter is
declared as:

ParameterBag $context = NULL

This makes the type implicitly nullable, which is deprecated in PHP 8.4 and will
become a fatal error in a future version.

Steps to reproduce

  1. Run Drupal with PHP 8.4.
  2. Trigger any code path that instantiates
    Drupal\conflict\Event\EntityConflictDiscoveryEvent without passing a
    $context argument (i.e. relying on the NULL default).
  3. Observe the PHP 8.4 deprecation notice:
    Implicitly marking parameter $context as nullable is deprecated, the
    explicit nullable type (?) must be used instead.

Proposed resolution

Add an explicit ? nullable marker to the $context parameter type hint in
EntityConflictDiscoveryEvent::__construct():

 // Before (PHP 8.4 deprecated):
 public function __construct(EntityInterface $local, EntityInterface $remote, EntityInterface $base, ParameterBag $context = NULL)

 // After (explicit nullable):
 public function __construct(EntityInterface $local, EntityInterface $remote, EntityInterface $base, ?ParameterBag $context = NULL)

The constructor body already handles a null value correctly via the null
coalescing operator ($this->context = $context ?? new ParameterBag()), so no
further changes are required.

Remaining tasks

  • Apply the patch.
  • Confirm no PHP 8.4 deprecation notices are emitted for this class.

User interface changes

None.

API changes

The signature of EntityConflictDiscoveryEvent::__construct() changes from an
implicitly nullable ParameterBag $context = NULL to an explicitly nullable
?ParameterBag $context = NULL. Callers that already pass NULL or omit the
argument are unaffected.

Data model changes

None.

Issue fork conflict-3575119

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

eduardo morales alberti’s picture

Issue summary: View changes

ishani patel made their first commit to this issue’s fork.

ishani patel’s picture

Assigned: Unassigned » ishani patel
Status: Active » Needs review

@eduardo morales alberti, I've raised MR.
Kindly review it.

Thank you!

ishani patel’s picture

Assigned: ishani patel » Unassigned