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
- Run Drupal with PHP 8.4.
- Trigger any code path that instantiates
Drupal\conflict\Event\EntityConflictDiscoveryEventwithout passing a
$contextargument (i.e. relying on theNULLdefault). - 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
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
Comment #2
eduardo morales albertiComment #5
ishani patel commented@eduardo morales alberti, I've raised MR.
Kindly review it.
Thank you!
Comment #6
ishani patel commented